2013-08-30 41 views
0

開始我SQL計數順序GOB

我有一個小問題,我匹配的一些文件每天FOT更新我的數據庫。 我想算我自一,月,日有多少訂單開始由「GOB」已經通過一天我的表「ORDER」

id|last_update 
gogo2132|27/08/2013 00:00:00 
gob00000|27/08/2013 00:00:00 
gob00001|27/08/2013 00:00:00 
gob00002|27/08/2013 00:00:00 
gob00003|28/08/2013 00:00:00 

結果我需要

Day|count"only id start by gob) 
27/08/2013| 3 
28/08/2013| 1 

謝謝

回答

0
SELECT orderdate, COUNT(*) 
FROM `ORDER` 
WHERE orderid LIKE 'GOB%' 
GROUP BY orderdate 
ORDER BY orderdate DESC 

如果orderdate不包含時間,這將是一個日計算。

1

我認爲你正在尋找下面的代碼。

Select count(*),order_date From Table 
Where Left(id,3) = 'Gob' And DateDiff(d,order_date,getdate()) <= 30 
Group by order_date 
0
SELECT orderdate, COUNT(*) 
FROM `ORDER` 
WHERE orderid LIKE 'gob%' AND last_update= (SELECT NOW() - INTERVAL 1 MONTH) 
GROUP BY DAY(last_update)