MYSQL IF SELECT COUNT()大于零select * from table,否则不返回任何内容
作者:互联网
我正在寻找一种查询方式,例如:
MySQL的:
示例:如果SELECT COUNT(column_XX)WHERE column_XX = value_XX FROM table_XX大于零(0),则选择所有内容或SELECT * FROM that table_XX WHERE column_XX = value_XX并返回所有数据…否则返回“未找到任何内容”或仅返回零(0)
简而言之,如果列中的所有值都大于零,我想从表列中选择所有数据,否则仅选择值≥= 1并返回所有值.
可以在此处应用哪种魔术功能以完成单个查询?…真的非常感谢.
解决方法:
您可以这样尝试:
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
)
标签:if-statement,count,select,where,mysql 来源: https://codeday.me/bug/20191122/2056881.html