-1
SELECT reg.name,
       SUM(donatecheck.donate)
FROM   reg,
       donatecheck
WHERE  reg.email = donatecheck.email
       AND SUM(donatecheck.donate) > 4000
GROUP  BY reg.name; 

有两个表regdonatecheck我想totaldonation从每个人的数据库中获取名称,并且不重复 ..donatecheckattributes==email,和catagorydonationreg table==name,email

4

1 回答 1

2

sum 之类的聚合函数不能在 WHERE 中使用,它们必须在 group by 中使用,使用 'HAVING' 关键字

SELECT reg.name,
       SUM(donatecheck.donate)
FROM   reg
       JOIN donatecheck
         ON reg.email = donatecheck.email
GROUP  BY reg.name
HAVING SUM(donatecheck.donate) > 4000; 
于 2013-08-05T20:19:36.947 回答