以下输出的Oracle SQL查询?

时间:2017-08-09 17:20:12

标签: sql oracle

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
  1. 我要根据date计算购买数。
  2. 我要根据userid计算购买数。

2 个答案:

答案 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