面试的SQL,求解答(我自己写的就不传啦,错了很多)
PS:另外求推荐练习SQL语句的资料书籍什么的,最近SQL好渣!!
------解决方案--------------------第一题
oracle 写法:
select * from (select ID from A order by CHENGJI) where rownum<=5
sqlse 写法:
select top 5 * from (select ID from A order by CHENGJI)
第二题
(1),select s.s#,s.sn from s s,c c ,sc sc where s.s#=sc.s# and sc.c#=c.c# and c.cn='税收基础'
(2),select s.sn, s.sd from s s,c c ,sc sc where s.s#=sc.s# and sc.c#=c.c# and c.c#='C2'
(3),select s.sn, s.sd form s where s.s# not in (select s.s# from s s,c c,sc sc where s.s#=sc.s# and sc.c#=c.c# and c.c#='C5')
(4),select s.sn, s.sd from s s,c c ,sc sc where s.s#=sc.s# and sc.c#=c.c# group by s.sn, s.sd having conunt(*)=
(select conunt(*) from c)
(5),select count(*) from s s,c c ,sc sc where s.s#=sc.s# and sc.c#=c.c#
(6),select s.sn, s.sd from s s,c c ,sc sc where s.s#=sc.s# and sc.c#=c.c# group by s.sn, s.sd having conunt(*)>5
------解决方案--------------------SQL的关键词就那几个:这是整个MySQL的;
手写,可能有错;
SELECT DISTINCT<select_list>
FROM <left_table>
<join_type>JOIN <right_table>
ON <join_condition>
WHERE <where_condition>
GROUP BY <group_by_list>
WITH {CUBE
------解决方案--------------------
ROLLUP}
HAVING <having_condition>
ORDER BY <order_by_list>
LIMIT <limit_number>