搂住你的sql不正确,你既然求field1 ,field2分组的话,这样field1,field2 必须在group by 中出现否则告诉你不正确。搂住你可以这样啊,这样是正确的sql 语句select sum(字段一)as t1,sum(字段二)as t2 into 临时表
form 正表 where 条件一(字段二的条件)
group by 字段0。for example:select sum(field1),sum(field2) into temparory_table
from table where field2 =condition1 group by field1
form 正表 where 条件一(字段二的条件)
group by 字段0。for example:select sum(field1),sum(field2) into temparory_table
from table where field2 =condition1 group by field1
我的意思是, sum(字段一) 的时候假没有条件限制,假设全部100条。。但是sum(字段二)的时候有一些条件限制,比如只50条,,而结果是按照一个字段归类的。
所以语句的意思应该是
select sum(字段一) as t1, sum(select 字段二 where 字段3=1) as t2 into 临时表 from 正表 group by 字段0
sql server中没问题,祝你好运!
select sum(字段1)as aa,sum(case when 字段3=1 then 字段2 end)as bb from 正表 group by 字段0
select sum(字段1)from 正表
select sum(字段2)from 正表 where 字段3=1
select (select sum(字段1)from 正表)as aa,(select sum(字段2)from 正表 where 字段3=1)as bb
查询1:查询成本(相对于批处理):24.58%
查询2:查询成本(相对于批处理):18.85%
查询3:查询成本(相对于批处理):18.85%
查询4:查询成本(相对于批处理):37.71%
估计用多条语句完成效率会更低!