我在3张表了查询了3条数据
select dwjc as '单位名称' from at_dm_scdw
where dwdm = '1086101000'
select count(dwdm) as '总井数' from at_dm_djjbxx
where dwdm like '%1086101000%'
select count(scsj) as '开井数' from it_sc_djrsc_cqsj
where scsj!=0 and dwdm like '%1086101000%'
现在我要把这3条数据放到一张临时表里,分别放3列
请问这个语句应该怎么写啊?希望各位师兄指点下小弟~
select dwjc as '单位名称' from at_dm_scdw
where dwdm = '1086101000'
select count(dwdm) as '总井数' from at_dm_djjbxx
where dwdm like '%1086101000%'
select count(scsj) as '开井数' from it_sc_djrsc_cqsj
where scsj!=0 and dwdm like '%1086101000%'
现在我要把这3条数据放到一张临时表里,分别放3列
请问这个语句应该怎么写啊?希望各位师兄指点下小弟~
(dwjc varchar(100) not null,
total int null,
scsj int null
)
insert into #temp (dwjc)
select dwjc from at_dm_scdw
where dwdm = '1086101000' declare @total int
delcare @scsj intselect @total = count(dwdm) as '总井数' from at_dm_djjbxx
where dwdm like '%1086101000%' update #temp set total = @totalselect @scsj =count(scsj) as '开井数' from it_sc_djrsc_cqsj
where scsj!=0 and dwdm like '%1086101000%' update #temp set scsj = @scsj
select * from #temp
drop table #temp
(select dwjc from at_dm_scdw
where dwdm = '1086101000' ) as '单位名称',
(select count(dwdm) from at_dm_djjbxx
where dwdm like '%1086101000%' ) as '总井数',
(select count(scsj) from it_sc_djrsc_cqsj
where scsj!=0 and dwdm like '%1086101000%' ) as '总井数'
into #temp