商品以省市方式显示百分比数量

SET @sql = 'SELECT DISTINCT dbo.ISS_Base_Commodity.Name [商品] ,SUM(Numer) [总销量]'
SELECT  @sql = @sql
        + ' ,CAST(ROUND(CAST(SUM(CASE dbo.ISS_System_Province.Name when '''
        + [省份]
        + ''' THEN Numer ELSE 0 END) AS FLOAT) / CAST(SUM(Numer) AS FLOAT), 4)  * 100 AS VARCHAR(20))+''%''  ['
        + [省份] + ']'
FROM    ( SELECT DISTINCT
                    Name [省份] ,
                    PKID
          FROM      dbo.ISS_System_Province
          GROUP BY  PKID ,
                    Name
        ) a 
SET @sql = @sql
    + 'FROM     ISS_Base_Commodity
				INNER JOIN ISS_Main_OrderInfo ON ISS_Base_Commodity.PKID = ISS_Main_OrderInfo.ISS_Base_Commodity_PKID
				INNER JOIN ISS_Base_Customer ON ISS_Main_OrderInfo.ISS_Base_Customer_PKID = ISS_Base_Customer.PKID
				INNER JOIN ISS_System_Province ON ISS_Base_Customer.ISS_System_Province = ISS_System_Province.PKID
			    GROUP BY ISS_Base_Commodity.Name'
			    PRINT @sql
EXEC(@sql)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值