我试图找到解决方案:
我需要查询选择所有不started
的任务,此任务的类似任务名称不应该多于此表中带有标记started
重复的5行
我的查询:
SELECT * FROM tasks as t
WHERE started = 0
AND ((SELECT COUNT(*) FROM tasks
WHERE started = 1 AND taskname = taskname) < 5)
但查询无效。谁能告诉我我做错了什么?
答案 0 :(得分:3)
尝试以下
AND taskname = t.taskname
答案 1 :(得分:1)
你非常接近:
SELECT * FROM tasks as t
WHERE started = 0
AND (SELECT COUNT(*) FROM tasks
WHERE started = 1
AND taskname = t.taskname) < 5
您只需要比较计数结果,而不是在子查询中包含比较。此外,您需要使用t.
前缀