Purchase Table
UserId Date Product
----------------------------
usr101 09-08-17 purchase
usr101 09-08-17 purchase
usr102 09-08-17 purchase
usr101 10-08-17 purchase
usr103 10-08-17 Purchase
usr103 10-08-17 Purchase
usr102 11-08-17 purchase
usr104 11-08-17 purchase
User Table
UserId Name
-----------------
usr101 Fidal
usr102 robert
usr103 Lenin
usr104 Marx
我想要以下输出:
name date count(purchase)
fidal 09-08-17 2
date
计算购买数。userid
计算购买数。答案 0 :(得分:0)
试试这个:
select u.Name,
p.Date,
count(1)
from purchase_table p
JOIN user_table u
ON p.UserId = u.UserId
group by u.Name,
p.Date
答案 1 :(得分:0)
select
B.name,
A.date,
count(*)
from
purchaseTable A,
userTable B
where
A.userId = B.userID
group by
B.name, A.date