select o.user_id as "User Id",
count(distinct o.id_order) as "Count(Order)",
count(distinct i.id_item) as "Count(Item)",
max("date") as "Date"
from orders o
join item i on o.id_order = i.id_order
group by user_id;
User Id Count(Order) Count(Item) Date
------- ------------ ----------- ----------
1 3 7 22.11.2018
SELECT user_id,
count(o.id_order),
count(item.id_item)
FROM USER
INNER JOIN
`ORDER` o ON user.id=o.id_order
INNER JOIN item i ON o.id_order=o.id_order
GROUP BY o.Date, o.id_order
2条答案
按热度按时间qkf9rpyu1#
尝试使用
distinct count
对于count columns
,和grouping by user_id
这就足够了:rextester演示
gpnt7bae2#
您必须对user、order和item表使用内部联接。对每个日期和顺序也使用GROUPBY子句。