首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

难的SQL语句

2012-02-13 
求一个难的SQL语句SQL语句:Select Product_id,Name,(sum(ppvalue +curvalue)) as totalvalue From product

求一个难的SQL语句
SQL语句:

Select Product_id,Name,(sum(ppvalue +curvalue)) as totalvalue From productpraise_cp_view group by product_id,name order by totalvalue desc

现在要求其中求和的ppvalue和curvalue 是来自表A中的isadauit列的值为1的才相加。视图中的PPVALUE和CURVALUE就是来自表A。





[解决办法]
Select Product_id,Name,(sum(case when isadauit=1 then ppvalue +curvalue else 0 end)) as totalvalue From productpraise_cp_view group by product_id,name order by totalvalue desc
[解决办法]

Select Product_id,
Name,
(sum( case when isadauit = 1 then ppvalue +curvalue else 0 end )) as totalvalue 
From productpraise_cp_view
group by product_id,name 
order by totalvalue desc
[解决办法]

SQL code
Select Select     Product_id,Name,    (select sum(ppvalue +curvalue) from productpraise_cp_view where product_id=a.product_id and Name=a.Name and  isadauit=1) as totalvalue From     productpraise_cp_view  agroup by     product_id,name order by totalvalue desc     select    Product_id,Name,    sum(case when isadauit=1 then ppvalue +curvalue else 0 end) as totalvaluefrom     productpraise_cp_viewgroup by     product_id,name order by totalvalue desc 

热点排行