r****r 发帖数: 1839 | 1 我照猫画虎写了一个
Select PurchaseID, ItemID, Date, LineNumber, count(MemberID) from Table1 t1
join Table2 t2 on t1.PurchaseID=t2.PurchaseID where t2.ItemID=‘手表’ group
by MemberID having count(MemberID) > 1
对吗? |
|
r****r 发帖数: 1839 | 2 Table1:
MemberID
PurchaseID
Table2:
PurchaseID
ItemID
Date
LineNumber
给出Table2中所有行,满足如下条件:
同一个Member在同一天里购买多于一次ItemID=‘手表’
前年我会这个,今年忘记了。多谢。
|
|
B*****g 发帖数: 34098 | 3 SELECT *
FROM (SELECT t2.*,
COUNT(*) OVER (PARTITION BY t1.MemberID, t2.Date) NumOfMulti
FROM table1 t1, table2 t2
WHERE t1.PurchaseID = t2.PurchaseID
AND t2.ItemID = '手表')
WHERE NumOfMulti > 1 |
|