A.输出其中第3,4行:
名字倒序:
select top 2 reverse(name) from t where id not in (select top 2 id from t order by id ) orde by id(查出结果是先第3行,再第4行数据)
输出顺序倒序:select top 2 * from t where id in (select top 4 id from t order by id) order by id desc(查出结果是先第四行,再第三行数据)
如果ID是连续的,直接:
SQL codeselect * from tb where id in(3,4) order by id desc
否则,要创建一个行序号:
SQL codeselect name,id from (
select *,rn=row_number()Over(order by id) from tb
)t where rn in(3,4) order by id desc
B.select a.作者编号,a.姓名,a.性别,b.出版社from 作者 a,图书 bwhere 年龄<(selectavg(年龄) from 作者) and a.作者编号=b.作者编号
Select a.aID, a.aName, a.aAge, b.bPress from author as a inner join books as b on a.aID= b.aIDwhere a.aAge< (selectavg(aAge)from author)
select a.作者编号,a.姓名,a.性别,b.出版社from 作者 AS a INNERJOIN 图书 AS b ON a.作者编号=b.作者编号INNER JOIN (selectavg(年龄)AS 年龄from 作者)AS c ON a.年龄<c.年龄
C.select 作者信息.作者编号 from 作者信息leftjoin 奖状信息 on 作者信息.作者编号=奖状信息.作者编号 where 作者信息.作者编号 is null
左连接,以左边的表为准,右边的表没有的补为null
select 作者编号 from 作者信息 except select 作者编号from 奖状信息select * from 作者信息
a where not exists(select 1 from 奖状信息 where 作者编号=a.作者编号)
D.求平均工资小于1000的员工编号,姓名,工资
select 职工号,姓名,avg(工资) 平均工资 from salary group by 职工号,姓名 having avg(工资) < 1000
select 职工号, 姓名,工资 from salary
where 职工号 in(select 职工号 from salary group by 职工号 having avg(工资)<1000)
A. http://topic.csdn.net/u/20111126/11/a7da4201-adc5-45c7-a703-90871849fca5.html
B. http://topic.csdn.net/u/20111124/13/484757e5-3c5e-492e-b7dc-d694003457a6.html
C. http://topic.csdn.net/u/20111108/19/a21c5a2b-a52a-4946-9da3-6dce08fab09e.html
D.http://topic.csdn.net/u/20120310/01/709d6569-f688-4c4d-8f5b-831f3d0356eb.html