数据库求助.谢谢!!

来源:百度知道 编辑:UC知道 时间:2024/05/14 05:35:06
sql="select sum(num) as total_in_num from sfa where name_id="&name_id&" and rq=date() and num<6 union select sum(num) as total_in_numm from sfa where name_id="&name_id&" and rq=date() and num>6 "
rs3.open sql,conn
数据库为access,为什么union后的东西无效?
简化一下
sql="select sum(a) as sum1 from table1 where b>0 union select sum(a) as sum2 from table1 where b<0 "
rs.open sql,conn
现在我需要在一个表中对同一个数据有条件求和,小弟谢谢各位了

完全不对,union指令的目的是将两个SQL语句的结果合并起来,而这两个SQL语句使用的是2张不同的表啊,你这个是一张表里,用union干什么啊,另外使用union主要注意两表字段数量相等,名字可以不一样,相应的字段类型应该也应该一致

老兄你这是两句查询