Simple SQL question

  1. select count(c.CustomerID)
  2.   from customers AS c INNER JOIN orders AS o
  3.   ON (c.CustomerID = o.CustomerID)
  4.     where DATE(o.PurchaseDateTime) BETWEEN CURDATE() - INTERVAL 1 MONTH AND CURDATE()
  5.      group by c.CustomerID
複製代碼
This results in every CustomerID joining with every order
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

select ..... order by ? limit 1, 1?

TOP

select ..... order by ? limit 1, 1?
杜龍 發表於 2013-9-8 13:05


+1, 先order by再limit
(假設你用緊MySQL)

TOP

加個max唔得?
select max(count(c.CustomerID)) ......

TOP

select ..... order by ? limit 1, 1?
杜龍 發表於 2013-9-8 13:05



    你1, 1 會選左第一個, 應該係 0, 1

TOP