我想计算从不同类别中选择的图像,我的查询返回错误
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'(选择计数(i1.id)作为cnt FROM image_gallery i1 LEFT OUTER JOIN image_g'在第2行附近使用正确的语法
我哪里错了?
SELECT count(*)
(select count(*)
FROM image_gallery i1
LEFT OUTER JOIN image_gallery i2
ON (i1.category_id = i2.category_id AND i1.id < i2.id)
GROUP BY i1.id
HAVING COUNT(*) < 10
) as total_pics
答案 0 :(得分:1)
您错过了FROM
关键字
SELECT sum(cnt)
FROM
(
select count(i1.id) as cnt
FROM image_gallery i1
LEFT OUTER JOIN image_gallery i2 ON i1.category_id = i2.category_id
AND i1.id < i2.id
GROUP BY i1.id
HAVING COUNT(*) < 10
) as total_pics