有下面2个表,
就是sales这个表中sales_rep有重复的。本人可以分组求和sum然后连接个表输出sum(value)大于1000的
本人想这么写不对。
SELECT first_name ,surname ,SUM(value) FROM sales LEFT JOIN sales_rep ON sales_rep = employee_number WHERE sum(VALUE) > 1000 GROUP BY sales_rep ;
求好心人告诉这个该怎么写,刚开始学者
就是sales这个表中sales_rep有重复的。本人可以分组求和sum然后连接个表输出sum(value)大于1000的
本人想这么写不对。
SELECT first_name ,surname ,SUM(value) FROM sales LEFT JOIN sales_rep ON sales_rep = employee_number WHERE sum(VALUE) > 1000 GROUP BY sales_rep ;
求好心人告诉这个该怎么写,刚开始学者
解决方案
40
select b.first_name , b.surname, a.* from
(
Select sales_rep, sum(VALUE) as sval from sales
group by sales_rep
having sval >1000
) AS a
inner join sales_rep AS b
on a.sales_rep = b.employee_number
(
Select sales_rep, sum(VALUE) as sval from sales
group by sales_rep
having sval >1000
) AS a
inner join sales_rep AS b
on a.sales_rep = b.employee_number