我在MySQL中有table
如下:
我正在尝试以下查询:
select * from test.score_card where playerId in(2,3);
select * from test.score_card where playerId not in(0);
我需要单行查询,以便它应该像我传递
一样显示输出 在WHERE IN子句中 playerId
然后它应该显示所选行或者如果我
不传递任何值,然后它应该选择所有行。
答案 0 :(得分:0)
所以a或STATEMENT?
SELECT * FROM test.score_card
WHERE playerId in (2,3)
UNION
SELECT * FROM test.score_card
WHERE (
SELECT count(*) FROM test.score_card
WHERE playerId in (2,3))=0 AND playerId not in (0);
如果计数在第一组上等于0,那么只会返回第二组的更复杂:
{{1}}
(未经测试,可能有拼写错误)