一张桌子,我想知道我的行总数。例如。这是我的表:
Date Fruit Sold Mon apple 4 Mon pear 5 Mon orange 2 Tues apple 3 Tues pear 2 Tues orange 1 The table I want back is: Fruit Sold apple 7 pear 7 orange 3
我可以做什么查询?然而,根据我的实际情况,我有数百种水果。那么我如何在每次都指出每种类型的水果时进行查询?
答案 0 :(得分:2)
这将是:
select fruit, sum(sold) as sold
from fruitsales
group by fruit
-- adding something like <<where date = 'Mon'>> if you want to limit it.
这将汇总每个sold
类型的各个fruit
列(通过汇总)。
答案 1 :(得分:2)
这是如何做到的:
select fruit, sum(sold)
from table
group by fruit
...欢呼声
答案 2 :(得分:0)
按时间分组
select fruit, sum(sold),substring(saletime,1,3) from table group by fruit,substring(saletime,1,3)