我有以下MYSQL查询工作:
SELECT
a.author_name, COUNT(*)
FROM
publication p,
authored a
WHERE
a.pubkey = p.pubkey
AND p.pubkey LIKE '%/asd/%'
GROUP BY a.author_name
HAVING COUNT(*) >= 1;
上述查询是显示在一本书中至少发布一本包含“asd”字样的图书的作者的姓名。
我的想法就是设定差异。我试图通过使用以下sql语句找到没有发布包含“asd”一词的书的作者:
SELECT
a.author_name
FROM
author a,publication p
WHERE
a.pubkey = p.pubkey AND a.author_name NOT IN (SELECT
a1.author_name, COUNT(*)
FROM
publication p1,
author a1
WHERE
a1.pubkey = p1.pubkey
AND p1.pubkey LIKE '%/asd/%'
GROUP BY a1.author_name
HAVING COUNT(*) >= 1);
但由于某种原因,我不断收到此错误“操作数应包含1列,我无法找到错误。
谢谢。
答案 0 :(得分:0)
尝试从内部查询中删除计数。这样的事可能......
SELECT
a.author_name
FROM
author a,publication p
WHERE
a.pubkey = p.pubkey AND a.author_name NOT IN (SELECT
a1.author_name
FROM
publication p1,
author a1
WHERE
a1.pubkey = p1.pubkey
AND p1.pubkey LIKE '%/asd/%'
GROUP BY a1.author_name
HAVING COUNT(*) >= 1);