这是我的代码:
SELECT Discount,
country,
count(country) AS total
FROM OrderDetails,
Customers
WHERE discount != 0
GROUP BY Discount,
country
HAVING ( count(country) > 0 )
ORDER BY discount DESC
我现在需要做的是,无法在任何地方找到,就是让计数(国家/地区)加上正确的折扣数字。这样我知道每个国家有多少折扣。 我到处寻找,我找不到任何东西。即使在我自己的论文中,我也是从学校毕业的。
所以这是带连接的代码,所以看一下它会更清楚:
select Discount, country, count(country) as total
from Orders O
join Customers C
on C.CustomerID = O.CustomerID
join OrderDetails OD
on OD.OrderID = O.OrderID
where discount != 0
group by Discount, country
having (count(country)>0)
order by discount DESC
答案 0 :(得分:0)
select c.country, sum(od.discount) as totalDiscount
from orders o
inner join customers c
on c.customerID = o.customerID
inner join orderDetails od
on od.orderID = o.orderID
where od.discount != 0
group by c.country
order by sum(od.discount) desc