• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

怎样能把查询所得插入到临时表中??

ttllhh 2004-02-17 11:08:00
用如下语句对数据库的表进行了查询,sql语名正确运行,运行结果如下

select a.class_name as "班级名称" , c.specialty_name as "专业名称",
count(b.Invoice_CID) as "收费人数",sum(b.Invoice_Charge) as "收费金额",
(select count(Invoice_CID) as "退费人数" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class),
(select sum(Invoice_Charge) as "退费金额" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class)
from sofom_class a join SOFOM_Inovice b
on b.invoice_class = a.class_id
join sofom_specialty c on a.class_specialty = c.specialty_id
where b.Invoice_CTime='2004-2-16' or b.Invoice_QTime='2004-2-12'
group by a.class_name,c.specialty_name,b.Invoice_class

班级名称 专业名称 收费人数 收费金额 退费人数 退费金额
计0103 计算机软件 5 330.0 2 130.0
计0104 计算机软件 3 110.0 0


现在我想把查询出来的结果集插入到一张临时表temp中
假设temp字段结构如下:
temp1 temp2 temp3 temp4 temp5 temp6

如何实现,谢谢。。。在线等



...全文
26 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
LoveSQL 2004-03-25
如果已经创建了该表
insert into #temp select * from yourtable where ...
如果没有该表
select * into #temp from yourtable where ...
回复
dlpseeyou 2004-03-25
select ...... into #temp from .... where....
回复
rouqu 2004-03-25
SELECT * INTO #TEM1 FROM
(
select a.class_name as "班级名称" , c.specialty_name as "专业名称",
count(b.Invoice_CID) as "收费人数",sum(b.Invoice_Charge) as "收费金额",
(select count(Invoice_CID) as "退费人数" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class),
(select sum(Invoice_Charge) as "退费金额" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class)
from sofom_class a join SOFOM_Inovice b
on b.invoice_class = a.class_id
join sofom_specialty c on a.class_specialty = c.specialty_id
where b.Invoice_CTime='2004-2-16' or b.Invoice_QTime='2004-2-12'
group by a.class_name,c.specialty_name,b.Invoice_class
) A
回复
leeboyan 2004-03-24
如果是追加:
insert into #temp select * from yourtable where ...
回复
leeboyan 2004-03-24
select * into #temp from yourtable where ...
回复
laughsmile 2004-03-24
select ... INTO #TEMP
from ...
where ...
group by ...
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2004-02-17 11:08
社区公告
暂无公告