关于vb sql 数据库
大神在帮帮忙吧sql="selectt1.*,t2.总金额from(select*from业务总表where序号in(selectmin(序号)from业务总表asa,(...
大神在帮帮忙吧
sql = "select t1.*, t2.总金额 from (select * from 业务总表 where 序号 in (select min (序号) from 业务总表 as a, (select 业务编号, max (金额) as 最大金额 from 业务总表 group by 业务编号) as b where a.业务编号 = b.业务编号 and a.金额 = b.最大金额 group by b.业务编号, b.最大金额)) as t1,(select 业务编号,sum(金额) as 总金额 from 业务总表 group by 业务编号) as t2 where t1.业务编号 = t2.业务编号"
我如何能实现把sql = "select *** form 格式改成 into,也就是说提取业务总表里的上述条件信息,然后把新建一张表,把信息存到新表里呢?
还有就是如果用这个方法,数据两过大,比如1万多条,会不会影响速度呢? 展开
sql = "select t1.*, t2.总金额 from (select * from 业务总表 where 序号 in (select min (序号) from 业务总表 as a, (select 业务编号, max (金额) as 最大金额 from 业务总表 group by 业务编号) as b where a.业务编号 = b.业务编号 and a.金额 = b.最大金额 group by b.业务编号, b.最大金额)) as t1,(select 业务编号,sum(金额) as 总金额 from 业务总表 group by 业务编号) as t2 where t1.业务编号 = t2.业务编号"
我如何能实现把sql = "select *** form 格式改成 into,也就是说提取业务总表里的上述条件信息,然后把新建一张表,把信息存到新表里呢?
还有就是如果用这个方法,数据两过大,比如1万多条,会不会影响速度呢? 展开
1个回答
展开全部
新建表的话,和查询速度1W条基本没什么太大差别吧
select t1.*, t2.总金额 into 新表--就在这加into 新表 即可
from
(select * from 业务总表 where 序号 in (select min (序号) from 业务总表 as a,
(select 业务编号, max (金额) as 最大金额 from 业务总表 group by 业务编号) as b
where a.业务编号 = b.业务编号 and a.金额 = b.最大金额 group by b.业务编号, b.最大金额)) as t1,
(select 业务编号,sum(金额) as 总金额 from 业务总表 group by 业务编号) as t2
where t1.业务编号 = t2.业务编号
更多追问追答
追问
into 可以新建表,那么如果表存在,直接覆盖用这个表呢???? 大神帮帮忙
追答
貌似只能
insert into 新表 。。。。。后边就是那句select 语句
但这个只能往表里追加数据
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询