搂住你的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
解决方案 »
- apache cxf 在Interceptor的handleMessage方法给客户端返回json
- 求助 工程下每个文件包里的东西都是做什么的?
- xml组装问题
- JSP中getInitParameter()是什么意思
- [ALL]两道面试题
- 数据库连接问题
- JUnit 对 SSH 中 Service的测试
- ChartDirector图表问题请教?
- 100分求助,jtable,tablemodel,database问题
- A servlet can have multiple instances within the same application server JVM only if the servlet implements ______ interface?
- 急!请问struts中怎样实现在一个页面中显示同一个actionform中的两组属性值?
- 急问struts中<bean:define>标记!!!
我的意思是, 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%
估计用多条语句完成效率会更低!