如何格式化此SQL查询

时间:2013-07-12 18:34:15

标签: sql

我对此完全陌生,想要运行单个查询并输出cdv文件

格式为:

CODE  |  Quant
46  |  4
57  |  10
810 |  2

查询每个代码:

select COUNT(*) from OrderItemInfo
where PriceCode = '46'
and PrepareDateTime between '2013-01-01' and '2013-12-31'

价格代码将从46,57,810等变化

我不确定它是否可以作为查询完成,或者我是否需要采用不同的方式来执行此操作,脚本或其他内容。

3 个答案:

答案 0 :(得分:1)

不知道你使用的SQL的哪种风格可能有些偏差,但我相信你想要一个Group By

SELECT PriceCode, COUNT(*)
FROM orderItemInfo
WHERE PrepareDateTime between '2013-01-01' and '2013-12-31'
GROUP BY PriceCode

答案 1 :(得分:0)

按PriceCode添加一个组,然后选择价格代码并计算(*)

 select COUNT(*),PriceCode from     OrderItemInfo where PriceCode = '46' and     PrepareDateTime between '2013-01-01' and     '2013-12-31'
group by PriceCode

答案 2 :(得分:0)

SELECT PriceCode, COUNT(*) 
FROM OrderItemInfo
WHERE PrepareDateTime between '2013-01-01' and '2013-12-31'
GROUP BY PriceCode
ORDER BY PriceCode
相关问题