我正在寻找一种方法来查询:
MySQL的:
示例: 简单来说,如果列中的所有值都大于零,我想从表列中选择所有数据,否则只选择值> = 1并返回所有值。 在单一查询中可以应用哪个魔术?...我真的非常感谢。IF
SELECT COUNT(column_XX) WHERE column_XX = value_XX
FROM table_XX
大于零(0
)然后SELECT
所有内容或SELECT * FROM
{ em> table_XX WHERE column_XX = value_XX
和返回所有数据......否则返回'找不到任何内容' 或只是ZERO(0
)< / p>
答案 0 :(得分:3)
你可以尝试这样:
SELECT * FROM table_XX
WHERE column_XX = (
SELECT column_XX FROM table_XX
WHERE column_XX = value_XX GROUP BY column_XX HAVING COUNT(column_XX) > 0
)
答案 1 :(得分:0)
这会有用吗?
SELECT * FROM test_enum;
+------+-------+----------+
| ID | Name | IsActive |
+------+-------+----------+
| 1 | Abdul | No |
| 1 | Abdul | Yes |
+------+-------+----------+
2 rows in set (0.00 sec)
SELECT * FROM test_enum WHERE EXISTS(SELECT * FROM test_enum WHERE IsActive = 'No') AND IsActive = 'No';
+------+-------+----------+
| ID | Name | IsActive |
+------+-------+----------+
| 1 | Abdul | No |
+------+-------+----------+
1 row in set (0.00 sec)