SQL笔试题2
面试sql笔试题目

面试sql笔试题目
好的,以下是一份可能的SQL笔试题目:
1. 写出查询所有学生成绩的SQL语句。
2. 写出查询学生表中年龄大于等于18岁的学生记录的SQL语句。
3. 写出查询学生表中年龄小于18岁且姓“张”的学生记录的SQL语句。
4. 写出查询学生表中年龄等于18岁且姓“李”的学生记录的SQL语句。
5. 写出查询学生表中年龄等于18岁或姓“李”的学生记录的SQL语句。
6. 写出查询学生表中年龄等于18岁或姓“李”且成绩大于等于90分的学生记录的SQL语句。
7. 写出查询学生表中年龄等于18岁或姓“李”且成绩大于等于90分,并按成绩从高到低排序的学生记录的SQL语句。
8. 写出查询学生表中年龄等于18岁或姓“李”且成绩大于等于90分,并取出前5条记录的SQL语句。
9. 写出查询学生表中年龄等于18岁或姓“李”且成绩大于等于90分,并取出最后一条记录的SQL语句。
10. 写出查询学生表中年龄等于18岁或姓“李”且成绩大于等于90分,并取出第3条至第5条记录的SQL语句。
数据库笔试题及答案

数据库笔试题及答案【篇一:sql数据库经典面试题(修改笔试题)(有答案)】部门,平均工资,要求按部门的字符串顺序排序,不能含有human resource部门,employee结构如下:employee_id, employee_name,depart_id,depart_name,wage 答:select depart_name, avg(wage)from employee where depart_name human resourcegroup by depart_name order by depart_name-------------------------------------------------------------------------- 29.给定如下sql数据库:test(num int(4)) 请用一条sql语句返回num的最小值,但不许使用统计功能,如min,max等答:select top 1 num from test order by num--------------------------------------------------------------------------33.一个数据库中有两个表:一张表为customer,含字段id,name;一张表为order,含字段id,customerid(连向customer中id的外键),revenue;写出求每个customer的revenue总和的sql语句。
建表 create table customer(id int primary key,name char(10))gocreate table [order](id int primary key,customerid int foreign key referencescustomer(id) , revenue float)go--查询select customer.id, sum( isnull([order].revenue,0) )from customer full join [order]on( [order].customerid=customer.id ) group by customer.idselect customer.id,sum(order.revener) from order,customer where customer.id=customerid group by customer.idselect customer.id, sum(order.revener ) from customer full join order on( order.customerid=customer.id ) group by customer.id5数据库(10)a tabel called “performance”contain:name and score,please 用sql语言表述如何选出score最high的一个(仅有一个)仅选出分数,select max(score) from performance仅选出名字,即选出名字,又选出分数: select top 1score ,name from per order by scoreselect name1,score from per where score in/=(selectmax(score) from per).....4 有关系 s(sno,sname) c(cno,cname) sc(sno,cno,grade)1 问上课程 db的学生noselect count(*) from c,sc where ame=db and o=o select count(*) from sc where cno=(select cno from c whereame=db)2 成绩最高的学生号select sno from sc where grade=(select max(grade) from sc ) 3 每科大于90分的人数select ame,count(*) from c,sc where o=o andsc.grade90 group by ameselect ame,count(*) from c join sc on o=o and sc.grade90 group by ame数据库笔试题*建表:dept:deptno(primary key),dname,locemp:empno(primary key),ename,job,mgr,sal,deptno*/1 列出emp表中各部门的部门号,最高工资,最低工资select max(sal) as 最高工资,min(sal) as 最低工资,deptno from emp group by deptno;2 列出emp表中各部门job为clerk的员工的最低工资,最高工资 select max(sal) as 最高工资,min(sal) as 最低工资,deptno as 部门号 from emp where job = clerk group by deptno;3 对于emp中最低工资小于1000的部门,列出job为clerk的员工的部门号,最低工资,最高工资select max(sal) as 最高工资,min(sal) as 最低工资,deptno as 部门号 from emp as bwhere job=clerk and 1000(select min(sal) from emp as a wherea.deptno=b.deptno) group by b.deptno4 根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资select deptno as 部门号,ename as 姓名,sal as 工资 from emp order by deptno desc,sal asc5 写出对上题的另一解决方法(请补充)6 列出张三所在部门中每个员工的姓名与部门号select ename,deptno from emp where deptno = (select deptno from emp where ename = 张三)7 列出每个员工的姓名,工作,部门号,部门名select ename,job,emp.deptno,dept.dname from emp,deptwhere emp.deptno=dept.deptno8 列出emp中工作为clerk的员工的姓名,工作,部门号,部门名select ename,job,dept.deptno,dname from emp,dept wheredept.deptno=emp.deptno and job=clerk9 对于emp中有管理者的员工,列出姓名,管理者姓名(管理者外键为mgr) select a.ename as 姓名,b.ename as 管理者 from emp as a,emp as b where a.mgr is not null and a.mgr=b.empno10 对于dept表中,列出所有部门名,部门号,同时列出各部门工作为clerk的员工名与工作select dname as 部门名,dept.deptno as 部门号,ename as 员工名,job as 工作 from dept,empwhere dept.deptno *= emp.deptno and job = clerk11 对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序select a.deptno as 部门号,a.ename as 姓名,a.sal as 工资 from emp as a where a.sal(select avg(sal) from emp as b wherea.deptno=b.deptno) order by a.deptno12 对于emp,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序select count(a.sal) as 员工数,a.deptno as 部门号 from emp as awhere a.sal(select avg(sal) from emp as b wherea.deptno=b.deptno) group by a.deptno order by a.deptno13 对于emp中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序select count(a.empno) as 员工数,a.deptno as 部门号,avg(sal) as 平均工资 from emp as awhere (select count(c.empno) from emp as c wherec.deptno=a.deptno and c.sal(select avg(sal) from emp as b where c.deptno=b.deptno))1 group by a.deptno order bya.deptno14 对于emp中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数select a.deptno,a.ename,a.sal,(select count(b.ename) from emp as b where b.sala.sal) as 人数 from emp as awhere (select count(b.ename) from emp as b whereb.sala.sal)5 数据库笔试题及答案第一套一.选择题1. 下面叙述正确的是ccbad ______。
sql笔试题及答案

sql笔试题及答案1. 题目1:查询员工表中工资大于5000的员工信息,并按照工资降序排列。
答案:SELECT * FROM 员工表 WHERE 工资 > 5000 ORDER BY 工资DESC;解析:使用SELECT语句查询员工表中满足工资大于5000的记录,并使用ORDER BY子句按照工资字段降序排列。
2. 题目2:统计订单表中每个客户的订单总数,并按照订单总数升序排列。
答案:SELECT 客户, COUNT(订单编号) AS 订单总数 FROM 订单表GROUP BY 客户 ORDER BY 订单总数 ASC;解析:使用SELECT语句查询订单表中每个客户的订单总数,并使用GROUP BY子句按照客户字段进行分组,COUNT函数用于统计订单编号,AS关键字用于为统计结果起别名,ORDER BY子句按照订单总数字段升序排列。
3. 题目3:查询学生表中不重复的学生姓名和对应的年龄。
答案:SELECT DISTINCT 学生姓名, 年龄 FROM 学生表;解析:使用SELECT DISTINCT语句查询学生表中不重复的学生姓名和对应的年龄。
4. 题目4:查询订单表中订单金额最大的订单信息。
答案:SELECT * FROM 订单表 WHERE 订单金额 = (SELECT MAX(订单金额) FROM 订单表);解析:使用SELECT语句查询订单表中订单金额等于最大订单金额的订单信息,使用子查询和MAX函数找出最大订单金额。
5. 题目5:查询销售表中每个月份的总销售金额。
答案:SELECT DATE_FORMAT(销售日期, '%Y-%m') AS 月份, SUM(销售金额) AS 总销售金额 FROM 销售表 GROUP BY DATE_FORMAT(销售日期, '%Y-%m');解析:使用SELECT语句查询销售表中每个月份的总销售金额,使用DATE_FORMAT函数将销售日期格式化成年月的形式,并使用SUM函数统计销售金额,使用GROUP BY子句按照月份进行分组。
sqlserver数据库笔试题和答案.doc

一单词解释 (2 分 / 个 ) 34分Data 数据 Database数据库RDBMS关系数据库管理系统GRANT 授权REVOKE取消权限 DENY 拒绝权限DECLARE 定义变量PROCEDURE存储过程事务主键Transactionprimary key触发器标识列TRIGGER 继续identity外键continue唯一foreign keyunqiue检查 check约束constraint二编写 SQL语句 (5 分 / 题 ) 50分(包含笔试题问题和解答答案)1)创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话Create table stu (学号int ,姓名 varchar(8),年龄 int,性别 varchar(4),家庭地址varchar(50),联系电话int);2)修改学生表的结构,添加一列信息,学历Alter table stu add学历varchar(6);3)修改学生表的结构,删除一列信息,家庭住址Alter table stu drop column家庭地址4)向学生表添加如下信息:学号姓名年龄性别联系电话学历1A22 男 123456 小学2B21 男 119 中学3C23 男 110 高中4D18 女 114 大学Insert into stu values(1, ’A’,22, ’男’ ,123456, ’小学’)Insert into stu values(2, ’B’,21, ’男’ ,119, ’中学’)Insert into stu values(3, ’C’,23, ’男’ ,110, ’高中’)Insert into stu values(4, ’D’,18, ’女’ ,114, ’大学’)5) 修改学生表的数据,将电话号码以11 开头的学员的学历改为“大专”Update stu set学历=’大专’where联系电话like‘11%’6)删除学生表的数据,姓名以C 开头,性别为‘男’的记录删除Delect from stu where性别=’男’and姓名like‘c%’7)查询学生表的数据,将所有年龄小于 22 岁的,学历为“大专”的,学生的姓名和学号示出来Select 姓名 , 学号 from stu where年龄<22 and学历=’大专’8)查询学生表的数据,查询所有信息,列出前25%的记录Select top 25 percent * from stu9)查询出所有学生的姓名,性别,年龄降序排列Select 姓名 , 性别 from stu order by年龄desc10)按照性别分组查询所有的平均年龄Select avg(年龄) from stu group by 性别三填空 (3 分 / 题 ) 36 分(包含笔试题问题和解答答案)1)索引分为__聚集索引___和__非聚集索引__在一张表上最多可以创建 1 个聚集索引_索引。
sql基础笔试题及答案

sql基础笔试题及答案一、选择题:1. 在计算机应用中,“计算机辅助设计”的英文缩写为___________。
A. CAD B. CAM C. CAE D. CAT2. 微型计算机中,再分称作中央处理单元(CPU)的就是指___________。
A.运算器和控制器 B.累加器和算术逻辑运算部件(ALU) C.累加器和控制器 D.通用寄存器和控制器3. 计算机系统的“主机”由___________形成。
A.CPU,内存储器及辅助存储器 B.CPU和内存储器C.存放在主机箱内部的全部器件 D.计算机的主板上的全部器件 4. 冯·诺依曼计算机工作原理的设计思想就是___________。
A.程序设计 B.程序存储 c.程序编制D.算法设计 5. 世界上最先同时实现的程序存储的计算机就是___________。
A.ENIAC B.EDSAC C.EDVAC D.UNIVAC6. 通常,在微机中标明的P4或奔腾4是指___________。
A.产品型号 B.主频 C.微机名称 D.微处理器型号7. 连接计算机系统结构的五大基本组成部件一般通过___________。
A.适配器B.电缆 c.中继器 D.总线8. 在计算机领域中通常用主频去叙述___________。
A.计算机的运算速度 B.计算机的可靠性 C.计算机的可以运转性 D.计算机的可扩充性9. 下列计算机接口中,可以直接进行“插拔”操作的是___________。
A.COM B.LPT C.PCI D.USB10. 在来衡量计算机的主要性能指标中,字长就是___________。
A.计算机运算部件一次能处置的二进制数据位数 B.8十一位二进制长度 C.计算机的总线数 D.存储系统的容量11. 在计算机领域中,通常用英文单词“BYTE”来表示___________。
A.字 B.字长 C.二进制位 D.字节12. 在计算机领域中,通常用英文单词“bit”去则表示___________。
sql笔试题及答案

sql笔试题及答案一、选择题1. SQL中的INNER JOIN和OUTER JOIN有什么区别?A. INNER JOIN用于查询两个表中有关联的数据,而OUTER JOIN用于查询所有数据,包括没有关联的数据。
B. INNER JOIN只能查询单个表,OUTER JOIN可以查询多个表。
C. INNER JOIN和OUTER JOIN没有区别,只是不同的命名方式。
D. 以上都不是。
答案:A2. 如何在SQL中创建一个新表?A. 使用CREATE TABLE语句。
B. 使用INSERT INTO语句。
C. 使用SELECT INTO语句。
D. 使用UPDATE语句。
答案:A3. 在SQL中,如何删除表中的重复记录?A. 使用DELETE语句。
B. 使用DROP语句。
C. 使用DISTINCT关键字。
D. 使用GROUP BY语句。
答案:C4. 以下哪个SQL语句用于查询表中的数据?A. SELECT * FROM table_name;B. INSERT INTO table_name (column1, column2) VALUES (value1, value2);C. UPDATE table_name SET column1 = value1 WHERE condition;D. DELETE FROM table_name WHERE condition;答案:A5. 如何在SQL中对查询结果进行排序?A. 使用ORDER BY子句。
B. 使用GROUP BY子句。
C. 使用HAVING子句。
D. 使用COUNT()函数。
答案:A二、填空题1. 在SQL中,______关键字用于从表中选择唯一的值。
答案:DISTINCT2. 若要在SQL中查询某个字段的平均值,应使用______函数。
答案:AVG()3. ______语句可以用来向数据库表中添加新的数据行。
答案:INSERT INTO4. 若要在SQL中查询特定条件下的数据,应使用______子句。
SQL常考笔试题

订单:#订单编号,总价,订购日期;
订单子项: #子项编号,订单编号,产品编号,订购数量;
该表最高符合第()范式。C
A. 一
B. 二
C. 三
D. 未规范化的
14. 创建sql语句如下:
create table userInfo
(
userId int identity(-1,1), 第1行
针对以下题目请选择正确答案(每道题目有一个或多个正确的答案)。针对每一道题目,所有答案都选对,则该题得分,否则不得分。
1. 数据库设计的最终目标不包括()。 (选择两项)BD
A. 高效
B. 满足范式要求
C. 安全
D. 表现设计者的技术实力
E. 易用
F. 便于将来扩展功能和容量
2. 有关数据冗余说法错误的是()。(选择一项)C
userName nvarchar(20) not null, 第2行
cardNO char not null, 第3行
age smallint(2), 第4行
address ntext(300) 第5行
)
执行时,会在第()行出现错误。(选择两项)DE
A. 1
A. exec scoreproc 1,@myscore output
print @myscore
B. exec scoreproc @id = 1,@myscore output
print @myscore
C. declare @myscore numeric(4,2)
exec scoreproc 1,@myscore output
sql经典笔试题一(含答案)

二编写SQL语句(5分/题)501) 创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话2) 修改学生表的结构,添加一列信息,学历3) 修改学生表的结构,删除一列信息,家庭住址4) 向学生表添加如下信息:学号姓名年龄性别联系电话学历1 A 22 男123456 小学2 B 21 男119 中学3 C 23 男110 高中4 D 18 女114 大学5) 修改学生表的数据,将电话号码以11开头的学员的学历改为“大专”6) 删除学生表的数据,姓名以C开头,性别为‘男’的记录删除7) 查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号示出来9) 查询出所有学生的姓名,性别,年龄降序排列10) 按照性别分组查询所有的平均年龄三填空(3分/题) 361)索引分为___聚簇索引__和_ 非聚簇索引___2) TRUNCATE TABLE(删除所有,不能回滚)命令是什么含义?和Delete from(删除一个或者多个记录,能回滚)表名有什么区别?2)说出以下聚合数的含义:avg ,sum ,max ,min , count ,count(*)Avg 求平均值Sum 求和Max 最大值Min 最小值Count 返回满足条件的记录Count(*)函数返回表中所有记录数:8) 视图可以更新吗?会影响到实际表吗?视图是可以更新的,视图只是基于基本表上的虚拟表,对视图的更新会直接影响到实际表create table student(stu_no varchar(4) primary key,stu_name varchar(10) not null,stu_age decimal(3,0),stu_sex char(2),stu_address varchar(255),stu_tel number(20))select * from studentalter table student add stu_xl varchar(20)alter table student drop column stu_addressinsert into student(stu_no,stu_name,stu_age,stu_sex,stu_tel,stu_xl) values('1','A','22','ÄÐ','123456','Сѧ')insert into student(stu_no,stu_name,stu_age,stu_sex,stu_tel,stu_xl) values('2','B','21','ÄÐ','119','ÖÐѧ');insert into student(stu_no,stu_name,stu_age,stu_sex,stu_tel,stu_xl) values('3','C','23','ÄÐ','110','¸ßÖÐ');insert into student(stu_no,stu_name,stu_age,stu_sex,stu_tel,stu_xl) values('4','D','18','Å®','114','´óѧ');insert into student(stu_no,stu_name,stu_age,stu_sex,stu_tel,stu_xl) values('5','D','18','Å®','114','´óѧ');update student set stu_xl='´óר'where stu_tel like'11%'delete from student where stu_sex='ÄÐ'and stu_name like'C%'select stu_no,stu_name from student where stu_xl='´óר'and stu_age <'22'select stu_name,stu_sex from student order by stu_age descselect avg(stu_age),stu_sex from student where stu_sex='ÄÐ'group by stu_sex查询重复个数select stu_name,count(*) from student group by stu_name having count(*)>1。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1、查找整个职员表的所有内容。
select *from employees2、查看雇员名字(last_name)。
select last_namefrom employees3、查看雇员编号、名字和工种。
select last_name,job_id,employee_idfrom employees4、显示所有雇员的姓名、工资并将DEPARTMENT_ID显示为(Department_Id)。
select last_name,salary,DEPARTMENT_ID as Department_Idfrom employees5、查找在60号部门工作的雇员。
select last_name+first_name name,department_idfrom employeeswhere departmet_id=606、要求查找职位为SH_CLERK和SA_MAN的雇员姓名(last_name)。
select last_name job_idfrom employeeswhere job_id in (’sh_clerk’,’sa_man’)7、查找职位不是SH_CLERK和SA_MAN的雇员工种及姓名。
将姓名显示为(first_name+last_name命名为”Name”)。
select first_name+last_name Name, job_idfrom employeeswhere job_id not in (’sh_clerk’,’sa_man’)8、查找哪些雇员的工资在2000到3000之间select *from employeeswhere salary between 2000 and 30009、查找哪些雇员的工资不在3000到5000之间select *from employeeswhere salary not between 3000 and 500010、查找first_name以D开头,后面仅有三个字母的雇员信息。
select *where first_name like ‘D___’ and first_name not like ‘d__ ‘11、查找last_name以K开头的雇员信息。
select last_name,first_name,department_idfrom employeeswhere last_name like ‘k%’12、查找名字以字母M开头,以l结尾,并且第三个字母为c的雇员名字(First_name)、工种和所在部门号select first_name,job_id,department_idfrom employeeswhere first_name like ‘m_c%l’13、查找哪些雇员的工种名不以SA开头。
select job_idfrom employeeswhere job_id not like ’sa%’14、查找没有奖金的雇员信息。
select *from employeeswhere commission_pct is null15、查找有奖金的雇员信息。
select *from employeeswhere commission_pct is not null16、查找30号部门里不是CLERK的雇员信息。
select *from employeeswhere department_id=30 and job_id not like ‘%clerk%’17、查找在30号部门工作或不是CLERK的雇员信息。
select *from employeeswhere department_id=30or job_id not like ‘%clerk%’查找60号部门且工资大于5000的员工的信息select *from employeeswhere department_id=60and salary>500018、按字母顺序显示雇员的名字(last_name)。
select last_namefrom employeesorder by last_name19、按部门号降序显示。
select * from employees order by department_id desc20、查找工资高于$2000的雇员信息,按部门号和雇员名字排序。
select * from employees where salary>2000 order by department_id,employee_id21、选择奖金高于5%的雇员信息SELECT FIRST_NAME, LAST_NAME, COMMISSION_PCTFROM dbo.EMPLOYEESWHERE (COMMISSION_PCT > .05)22 查询年工资高于50000的员工信息select * from employees where 12*salary>5000023 查询奖金高于5000的员工姓名day1、查出部门地区编号为1700的员工姓名select first_name,last_name,city,department.location_idfrom locations,employees,departmentwhere locations.location_id=department.location_idand locations.location_id=17002、查询工作地区为北京的员工名及工资信息select first_name,last_name,salary,commission_pct,cityfrom locations,employees,departmentswhere departments.location_id=locations.location_idand departments.department_id = employees.department_idand departments.location_id=17003、查询薪水标准为B类的员工名称和员工薪水以及工资类别名称select last_name,first_name,salary,commission_pct,grafrom departments d,employees e,job_grades jwhere e.salary between j.lowest and j.highestand j.gra=’b’and d.department_id=e.department_id4、查询出主管Raphaely管理的员工和薪水信息select st_name+a.first_name as name, a.salary,mission_pct,st_name from employees a,employees bwhere a.department_id=b.department_idand s t_name like ‘%raphaely%’5、查出雇员所在的部门,并将没有雇员的部门的记录也显示出来。
select st_name+e.first_name as name,d.department_idfrom departments dleft outer join employees eon (e.department_id=d.department_id)6、查询出没有分配部门的员工信息select st_name+e.first_name as name,e.department_idfrom departments dleft outer join employees eon (e.department_id=d.department_id)where d.department_id is null7、计算每个部门的平均工资和工资总和select department_id,sum (salary) sum,avg (salary) avgfrom employeesgroup by department_id8、查询每个部门的每个工种的雇员数select count(*)num,department_id,job_idfrom employeesgroup by department_id,job_id9、请算出employee表中总雇员数量select count(*)from employee10.请算出employee表中所有雇员的平均工资select avg(salary)from employee11.请查询出employee表中的最低工资select min(salary)from employee12.请查询出employee表中最高工资select max(salary)from employee13、请计算出每个部门的平均工资、最高工资和最低工资select max(salary) max,min(salary) min,avg(salary) avg,department_idfrom employeegroup by department_id14、查询按部门名称分组工资总和大于4200的部门名称、工资和select department_name,sum(salary)from employees e,departments dwhere e.department_id=d.department_idgroup by department_namehaving sum(salary)>4200test0011.请查询出employee表中最低工资的雇员select last_namefrom employeewhere salary=(select min(salary) from employee)2.请查询出employee表中最高工资的雇员select last_namefrom employeewhere salary=(select max(salary) from employee)3、查询工资高于105号雇员的last_name,并且工种与他相同的雇员情况。
select last_name,job_id,salaryfrom employeeswhere salary>(select salary from employees where employee_id=’105′)and job_id=(select job_id from employees where employee_id=’105′)4、查询工资高于或等于30号部门工资最高额的雇员。