1
此表存储谁购买了哪本书以及何时购买的数据。我想知道哪些书是由USERID#1首先购买的。 SQL fiddleMysql select min in userid userid =?
这将导致
USERID BOOKID DATE_PURCHASE
1 2 2014-03-22 (purchased only by USERID #1)
1 5 2014-03-29 (purchased earlier than USERID #2)
1 6 2014-03-28 (purchased earlier than USERID #3)
1 7 2014-03-26 (purchased earlier than USERID #3)
它不显示BOOKID#3,因为这本书是由USERID#2第一次购买。
请注意,该表可能包含数以万计的行,所以我需要一个有效的解决方案。
如果不得不做手工,我会做这样的:
1. Check what books did USERID #1 buy
2. Go through all rows with those books (BOOKID) and check the MIN(DATE_PURCHASE) for each row
3. Write out those rows only where the USERID = #1
我不明白你想达到什么。用'this'和'This'太宽泛,请指明你的需要。 – 2015-04-05 08:57:05
如果用户#1在用户#2的同一天购买了该书,并且没有人比他早购买该书,该怎么办? – eggyal 2015-04-05 09:00:25