问题在于:我有一张包含销售数字(价格,日期,商店)的表格。商店并不重要,但我需要一个查询生成结果,如本例
Date Price
12/01/2012 100
12/01/2012 150
12/01/2012 270
13/01/2012 50
13/01/2012 150
13/01/2012 230
14/01/2012 330
结果表应如下所示
Date 0-100 100-200 200-300 300-400
12/01/2012 0 1 1 0
13/01/2013 1 1 1 1
所以基本上我需要一个查询来自动识别表格中的所有独特日期,然后计算每天每个价格范围内的销售额
如果这是平庸的,我道歉,我正在学习SQL。顺便说一句,这是SQLite3 我猜你的答案可以用于任何SQL falvour但请记住我将不得不使用sqlite
提前致谢 ç
答案 0 :(得分:0)
SELECT Date,
SUM(Price BETWEEN 0 AND 99) AS '0-100',
SUM(Price BETWEEN 100 AND 199) AS '100-200',
SUM(Price BETWEEN 200 AND 299) AS '200-300',
SUM(Price BETWEEN 300 AND 399) AS '300-400'
FROM MyTable
GROUP BY Date