mysql从y中选择a,b,其中a = 1且b不等于空白

时间:2018-03-27 01:19:01

标签: mysql

关于语法的基本问题和/或是否可以完成

如何从符合特定条件的列中选择所有值?

mysql> SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2;
+--------+------------------------+
| l_legs | a_calling_rtcp_mos_fs1 |
+--------+------------------------+
| 2      | 43                     |
| 2      | 43                     |
| 2      | 35                     |
| 2      |                        |
| 2      | 43                     |
| 2      | 43                     |
| 2      | 43                     |
| 2      | 10                     |
| 2      | 10                     |
| 2      | 43                     |
+--------+------------------------+
10 rows in set (0.00 sec)

这是我的尝试:

mysql> SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2 AND l_legs NOT = "";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= ""' at line 1

我想要的是从输出中删除a_calling_rtcp_mos_fs1列中的空格,这样我就会获得9行。

3 个答案:

答案 0 :(得分:0)

SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2 AND a_calling_rtcp_mos_fs1>0
    -> ;
+--------+------------------------+
| l_legs | a_calling_rtcp_mos_fs1 |
+--------+------------------------+
| 2      | 43                     |
| 2      | 43                     |
| 2      | 35                     |
| 2      | 43                     |
| 2      | 43                     |
| 2      | 43                     |
| 2      | 10                     |
| 2      | 10                     |
| 2      | 43                     |
+--------+------------------------+
9 rows in set (0.00 sec)

答案 1 :(得分:0)

如果是空白,请尝试:

SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2 AND
a_calling_rtcp_mos_fs1 != ' ';

如果是null试试这个:

SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2 AND
a_calling_rtcp_mos_fs1 is not null;

答案 2 :(得分:0)

NOT在 条件之前 ,而不是在其中间。

所以而不是:

l_legs NOT = ""

执行:

NOT l_legs = ""


最终选择:

SELECT l_legs,a_calling_rtcp_mos_fs1 from ims_calls where l_legs=2 AND NOT l_legs = "";