作者: luckiejacky 時間: 2013-9-8 11:23 標題: Simple SQL question
- select count(c.CustomerID)
- from customers AS c INNER JOIN orders AS o
- ON (c.CustomerID = o.CustomerID)
- where DATE(o.PurchaseDateTime) BETWEEN CURDATE() - INTERVAL 1 MONTH AND CURDATE()
- group by c.CustomerID
So if I have 6 customers
The results will be
6
1
1
1
1
1
How can I only get the first number, but I need o.PurchaseDateTime
Because I want to include the range of dates in the query.
Thanks
作者: 杜龍 時間: 2013-9-8 13:05
select ..... order by ? limit 1, 1?
作者: KinChungE 時間: 2013-9-8 15:46
+1, 先order by再limit
(假設你用緊MySQL)
作者: 神秘二代 時間: 2013-9-8 20:53
加個max唔得?
select max(count(c.CustomerID)) ......
作者: franklee006 時間: 2013-9-9 09:58
你1, 1 會選左第一個, 應該係 0, 1

