补充:测试通过,结合测试例子说明我觉得你应该有另外一个表是用来存商品的价格的这样比较通用一点如
type char(10) ,price inttype price1
102
20......设这个表为product 你原来给的那个表为selling(type char(10),sub char(10),qty int)我随便设几个数据进去typesubqty1
a
21
b
22
c
12
a
5那么有select sub,sum(price*qty) as sum_of_sub from (
select selling.type,sub,qty,price
from product,selling
where product.type=selling.type
) as temp_tablegroup by temp_table.suborder by temp_table.sub;语句我尽量少用别名,好理解一点结果会显示出所有sub的消费总额为 sub
sum_of_suba
120b
20c
20这个语句是通用的,多少种商品,多少个客户,多少比买卖都可以
|