sql基础面试题及答案
㈠ sql语句问题 面试题
select * from Voucher where 发生额>(select 发生额 from Voucher where 科目代码=101)
㈡ ★●问个SQL面试题
这个肯定可以
delete from student t
WHERE EXISTS (SELECT 1 FROM student WHERE t.Name = Name AND ID <t.id)
保留的是相同name下面id最小的
delete from student t
WHERE EXISTS (SELECT 1 FROM student WHERE t.Name = Name AND ID >t.id)
保留的是相同name下面id最大的
㈢ SQL 面试题
SELECT aa.日期, aa.数值, SUM(lj.数值) AS 累计
FROM 累积 lj INNER JOIN
(SELECT *
FROM 累积) aa ON lj.日期 <= aa.日期
WHERE (aa.日期 <= '2005-05-04') --日期可以变成时间段
GROUP BY aa.日期, aa.数值
ORDER BY aa.日期
㈣ sql面试题
1.insert into table_b
select * from table_a
2.delete from table_a as a
where exists
(
select * from table_b as b
where b.Name=a.name
and b.text=a.text
)
删除B表的语句差不多。
3.分页网上很多答案,可以去查,而且,数据库不同,用到的函数也不同。oracle数据库用rownum进行分页,SQL SERVER使用rownum() over()或top。
4.insert into table_c(name,text,number)
select name,text, rownum from table_a
union all
select name,text, rownum from table_b
这是Oracle写法
㈤ sql查询面试题
这个问题我是这样想的:
由于找的是ID,所以首先是SELECT ID FROM table_name
要找有多条记录的ID,所以条件是COUNT(ID)>1
这样找出来的会有重复ID,然后再根据ID分组就可以了
完整的语句就是:
SELECT ID
FROM table_name
WHERE COUNT(ID)>1
GROUP BY ID
对这个题我有这么两点总结:
1 平时我们一说ID,一般就是指的主键列,可这个题不是,ID列只是一个普通列,或者是一个外键而已。
2 由于要找的ID有多条记录,如果不分组找出来的就会有重复,这样就跟题目有些不符,所以要有分组
㈥ 1.一道SQL语句面试题
SELECT the_date,
(SELECT COUNT(*) FROM T AS T1 WHERE T1.the_date=T.the_date AND T1.the_type='胜') AS 胜,
(SELECT COUNT(*) FROM T AS T1 WHERE T1.the_date=T.the_date AND T1.the_type='负') AS 负
FROM T GROUP BY the_date
㈦ 你好,我想问我想用sql来存储一些试题,要怎么实现
你的这个实际上就是要用C#做一个试卷生成系统
这个还是有相当的工作量的
首先你基本概念有问题
SQL是一门语言,它不能存储任何内容的,甚至它都不是一个软件,而仅仅是一个语言标准
(如C/C++语言一样)
而存储你的试题的,要用到数据库,而数据库是支持SQL语言的
数据库有很多种的,常用的有ORACLE/SQLSERVER/SYBASE/MYSQL/ACCESS/....当然,还有最小型的SQLITE
在使用数据库前,你必须安装数据库软件(系统本身是不带的)
而要使用数据库,你当然要学习SQL语言
你要存储试题,要对试题的要素进行提取并生成一个表
如编号/分类/内容/难度...若有需要,还要放答案
然后用SQL语言,建立这样一张表
并将你的数据通过SQL导入,或用C#调用SQL进行输入
最后才是用C#对该试题库进行管理,随机抽取题目组成一张试卷
一个熟练的程序员(月薪2w的那种),一周应该可以做出来
学生的话,可以做为一个课程设计,一个月应该能完成一个简单的框架(当然,前提是你已掌握基础的数据库及编程知识)
㈧ SQL语句面试题
SELECT*,
(SELECTCOUNT(*)FROM(SELECTCOUNT(*),b.sidFROMscbLEFTJOINcoursecONb.Cid=c.CidGROUPBYb.sid,c.tid)owWHEREow.sid=a.sid)as'
选课数量',
(SELECTsum(Score)FROMScdWHEREa.sid=d.sid)as'总成绩'
FROMstudenta
;
SELECTd.sid,d.snamefromteachera
LEFTJOINcoursebona.tid=b.tid
LEFTJOINscconc.cid=b.cid
leftJOINstudentdONd.sid=c.sid
WHEREa.tname='叶萍';
SELECTsid,sname
FROMstudent
WHEREsidin(selecta.sid
FROMscAleftjoinscbona.sid=b.sid
WHEREa.cid=1andb.cid=2anda.score>b.score)
SELECTsc.Sid,sum(CASEWHENc.Cname='
数学'thensc.Scoreelse0end)数学,SUM(casewhenc.Cname='物理
'THENsc.ScoreELSE0END)物理,AVG(sc.Score)平均分
FROMsc
INNERJOINCourseconsc.Cid=c.Cid
WHEREc.Cnamein('数学','物理')
GROUPBYsc.Sid
ORDERBYAVG(sc.Score)DESC
insertintoSc(Sid,Cid,Score)values(003,3,85);
insertintoSc(Sid,Cid,Score)values(003,3,30);
首先这个不知道是你i写错了还是怎么一个人化学成绩有2个所以我在这里按照你这个上做的查询所以有一个人是选了单个课程
㈨ sql语句 面试题
A.创建表格CODE省略
注明:学生表PK stu_id 课程表pk cos_id 分数表PK enrollment_id FK stu_id,cos_id
B.插入数据code省略
C.Query
select s.stu_id,stu_name,count(cos_id) from student s,enrollments e where s.stu_id = e.stu_id and e.grade>60 group by s.stu_id,stu_name;
select e.stu_id,s.stu_name,c.cos_name from student s,enrollments e,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name = 'CHINESE'
and s.stu_name like 'W%';
select stu_id,stu_name from (select e.stu_id,stu_name,cos_name from enrollments e,student s,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name IN ('CHINESE','MUSIC'))
group by stu_id,stu_name
having count(cos_name) = 2
select distinct e.cos_id,c.cos_name,count(e.stu_id) stu_count,count(e.stu_id)-NVL(A.FAIL,0) upscore,(count(e.stu_id)-NVL(A.FAIL,0))/count(e.stu_id) rate from
(select cos_id,count(stu_id) fail from enrollments where grade<60 group by cos_id) a,enrollments e,course c
where e.cos_id = a.cos_id(+)
and e.cos_id = c.cos_id
group by e.cos_id,NVL(a.fail,0),c.cos_name;
update student
set avg_grade =(select avg(grade) X from enrollments group by stu_id
having student.stu_id = enrollments.stu_id);
select stu_id,avg(grade) from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id
having count(*)<=2
UNION
select A.stu_id,avg(A.grade)from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments) A,
(select stu_id,count(*) c from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id) B
where A.stu_id = B.stu_id
and A.x>1 and x<B.c
group by A.stu_id,b.c
_________________________________________________
环境:oracle 10g/TOAD 以上代码均通过测试,如有问题,请联系,谢谢
㈩ SQL面试题
select name
from
(
select name,sum(score) sc
from 表
group by name
) t1
where t1.sc>200
这样?