早教吧 育儿知识 作业答案 考试题库 百科 知识分享

SQL多语句合成一个句子selectemployeenameas姓名,count(ondutystatus)as数量into##tempfromproddutyswhereondutystatus='请假(病假)'anddatepart(yy,date)=2010groupbyemployeenameorderby数量descselect*from##tempwhere

题目详情
SQL 多语句合成一个句子
select employeename as 姓名,count(ondutystatus)as 数量 into ##_temp from proddutys where ondutystatus='请假(病假)'and datepart(yy,date)=2010 group by employeename order by 数量 desc
select * from ##_temp where 数量 in(select distinct top 2 数量 from ##_temp )
这两个SQL 语句如何合成一条SQL语句.
▼优质解答
答案和解析
其实很简单,在第一条语句后面加一个英文的分号就行了,这样执行查询就会得到两个记录集(在ASP.NET中是一个DATASET中的两张表),接着按你实际需求去使用哪一张表就行了!
select employeename as 姓名,count(ondutystatus)as 数量 into ##_temp from proddutys where ondutystatus='请假(病假)'and datepart(yy,date)=2010 group by employeename order by 数量 desc;select * from ##_temp where 数量 in(select distinct top 2 数量 from ##_temp )