SQL server 2000中如何实现以下乘法

[复制链接]
查看11 | 回复2 | 2007-8-10 16:12:12 | 显示全部楼层 |阅读模式
select sub,sum(qty1) from(select sub,case type when 1 then qty*10 when 2 qty*20 end as qty1from tablename)a group by sub先算出每笔的消费额,再汇总
回复

使用道具 举报

千问 | 2007-8-10 16:12:12 | 显示全部楼层
补充:测试通过,结合测试例子说明我觉得你应该有另外一个表是用来存商品的价格的这样比较通用一点如
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这个语句是通用的,多少种商品,多少个客户,多少比买卖都可以
回复

使用道具 举报

千问 | 2007-8-10 16:12:12 | 显示全部楼层
SQL Server数据中运算符与表达式
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行