MySQL选择distinct,但仅当所有第二列=1时?

MySQL选择distinct,但仅当所有第二列=1时?,mysql,sql,distinct,Mysql,Sql,Distinct,我希望这只是不返回任何东西。我该怎么做 mysql> select distinct (search_num), complete from Table where complete = '1'; +------------+----------+ | search_num | complete | +------------+----------+ | 1825 | 1 | +------------+----------+ 因为实际上有一(或多)行仍然是0,

我希望这只是不返回任何东西。我该怎么做

mysql> select distinct (search_num), complete from Table where complete = '1';
+------------+----------+
| search_num | complete |
+------------+----------+
|       1825 |        1 |
+------------+----------+
因为实际上有一(或多)行仍然是0,如图所示:

mysql> select distinct (search_num), complete from Table;
+------------+----------+
| search_num | complete |
+------------+----------+
|       1825 |        1 |
|       1825 |        0 |
+------------+----------+

我该怎么做呢?

这里的一种方法是通过
search_num
进行聚合,然后断言出现的唯一
complete
值是1

mysql> select distinct (search_num), complete from Table where complete = '1';
+------------+----------+
| search_num | complete |
+------------+----------+
|       1825 |        1 |
+------------+----------+
SELECT search_num
FROM yourTable
GROUP BY search_num
HAVING MIN(complete) = MAX(complete) AND MIN(complete) = 1;

这里的一种方法是通过
search\u num
进行聚合,然后断言出现的唯一
complete
值是1

SELECT search_num
FROM yourTable
GROUP BY search_num
HAVING MIN(complete) = MAX(complete) AND MIN(complete) = 1;

distinct
不是函数,它是
select distinct
的一部分,适用于整个选定行。跳过那些额外的括号以使代码更清晰,即只需编写
select distinct search\u num,complete…
distinct
不是一个函数,它是
select distinct
的一部分,并应用于整个选定行。跳过那些额外的括号以使代码更清晰,即只需写
选择distinct search\u num,complete…