我
我有一个小问题我每天都会匹配一些文件更新我的数据库。 我想算一下“GOB”开始的订单数是多少,自我1个月以来一直在我的餐桌上“订购”
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 :(得分:1)
我认为你正在寻找代码。
Select count(*),order_date From Table
Where Left(id,3) = 'Gob' And DateDiff(d,order_date,getdate()) <= 30
Group by order_date
答案 1 :(得分:0)
SELECT orderdate, COUNT(*)
FROM `ORDER`
WHERE orderid LIKE 'GOB%'
GROUP BY orderdate
ORDER BY orderdate DESC
如果订单日期不包含时间,则这是每日计数。
答案 2 :(得分:0)
SELECT orderdate, COUNT(*)
FROM `ORDER`
WHERE orderid LIKE 'gob%' AND last_update= (SELECT NOW() - INTERVAL 1 MONTH)
GROUP BY DAY(last_update)