我正在尝试从一个表中选择数据。
此查询效果很好:
SELECT * FROM game WHERE NOT (type = 'unity')
AND (cat_id='3d' OR cat2_id='3d' OR cat3_id='3d')
ORDER BY hits desc limit 120, 70
但我需要使用published = 1
运行它SELECT * FROM game WHERE NOT (type = 'unity')
AND (cat_id='3d' OR cat2_id='3d' OR cat3_id='3d')
AND published=1
ORDER BY hits desc limit 120, 70
此时我看到结果为0行,但应该是50行。
答案 0 :(得分:1)
这意味着条件与额外条件AND published=1
不匹配,因此没有记录返回。如果你说NOT (type = 'unity')
,我可以再次说(type != 'unity')
,而不是说SELECT * FROM game
WHERE (type != 'unity')
AND published=1
AND '3d' in (cat_id, cat2_id, cat3_id)
ORDER BY hits desc
limit 120, 70;
。
您可以尝试修改您的查询,如下所示
published=1
如果您确定新条件SELECT * FROM
(
SELECT * FROM game WHERE NOT (type = 'unity')
AND (cat_id='3d' OR cat2_id='3d' OR cat3_id='3d')
ORDER BY hits desc limit 120, 70
) xxx WHERE published=1;
它应该返回50行,那么尝试将该条件作为外部查询条件添加到SQL,其工作方式如下,并查看它返回的结果。
onClick_Start