亲爱的我有下面的查询,以计算有多少垃圾邮件为每个用户和总订单
我做了左边的加入,因为不是所有的订单都有垃圾邮件
select users.firstName,users.lastName,users.Id,users.phoneNumber,count(CASE
WHEN comments.`commentType` = "spam" THEN 1 ELSE NULL END) as countSpam,
count(`orders`.`id`) as totalOrder
from `orders`,users,providers
LEFT JOIN comments ON `orders`.`id`= `comments`.`commentableId`
where
`orders`.`providerId` = `providers`.id
and
users.id = `providers`.userId
and
`orders`.`createdAt` >= (CURDATE() - INTERVAL 7 DAY)
GROUP BY users.id
ORDER BY countSpam DESC;
我从mysql得到以下错误
“on子句”中的未知列“orders.id”
这里有什么问题?我做了左连接正确的基础上,旧的查询工作良好
1条答案
按热度按时间vfh0ocws1#
我修复了这个问题,我认为这是语法问题,下面是一个新的查询