-1

我试图找到一个解决方案:

我需要选择所有任务的查询,这些任务不是started和此任务的类似任务名称不应该在此表中重复 5 行并带有标志started

我的查询:

SELECT * FROM tasks as t 
WHERE started = 0 
AND ((SELECT COUNT(*) FROM tasks 
WHERE started = 1 AND taskname = taskname) < 5)

但查询不起作用。谁能告诉我我做错了什么?

4

2 回答 2

3

尝试以下

AND taskname = t.taskname
于 2012-12-08T22:23:09.757 回答
1

你非常接近:

SELECT * FROM tasks as t 
WHERE started = 0 
AND (SELECT COUNT(*) FROM tasks 
WHERE started = 1 
AND taskname = t.taskname) < 5

您只需要比较计数结果而不是在子查询中包含比较。t.此外,您需要使用前缀将任务名限定为外部表

于 2012-12-08T22:25:04.027 回答