程序员面试--选择题

上传人:小****克 文档编号:333386706 上传时间:2022-09-02 格式:PDF 页数:8 大小:319.16KB
返回 下载 相关 举报
程序员面试--选择题_第1页
第1页 / 共8页
程序员面试--选择题_第2页
第2页 / 共8页
程序员面试--选择题_第3页
第3页 / 共8页
程序员面试--选择题_第4页
第4页 / 共8页
程序员面试--选择题_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《程序员面试--选择题》由会员分享,可在线阅读,更多相关《程序员面试--选择题(8页珍藏版)》请在金锄头文库上搜索。

1、选择题选择题 44. 每个月份的发生额都比 101 科目多的科目请用 SQL 语句实现:从 TestDB 数据表中查询出所有月份的发生额都比 101 科目相应月份的发生额高的科目。请注意:TestDB 中有很多科目,都有 112 月份的发生额。表名:TestDB字段:AccID:科目代码,Occmonth:发生额月份,DebitOccur:发生额。答案:SELECT DISTINCT t1.AccID FROM TestDB t1 INNER JOIN TestDB t2 ONt2.Occmonth=t1.OccMonth AND t1.DebitOccurt2.DebitOccur ANDt

2、2.AccID=10145. 统计每年每月的信息year month amount1991 1 1.11991 2 1.21991 3 1.31991 4 1.41992 1 2.11992 2 2.21992 3 2.31992 4 2.4查成这样一个结果year m1 m2 m3 m41991 1.1 1.2 1.3 1.41992 2.1 2.2 2.3 2.4答案一:select sales.year ,(select t.amount from sales t where t.month=1 and t.year= sales.year)1,(select t.amount from

3、 sales t where t.month=1 and t.year= sales.year)2,(select t.amount from sales t where t.month=1 and t.year= sales.year)3,(select t.amount from sales t where t.month=1 and t.year= sales.year) as4from sales group by year;答案二:SELECTsales.year,GROUP_CONCAT(CONCAT(sales.year,:,sales.amount) FROM sales GR

4、OUP BY sales.year45. 显示文章标题,发帖人、最后回复时间表:id,title,postuser,postdate,parentid准备 sql 语句:drop table if exists articles;create table articles(id int auto_increment primary key,title varchar(50),postuser varchar(10), postdate datetime,parentid int referencesarticles(id);insert into articles values(null,第一

5、条,张三,1998-10-10 12:32:32,null),(null,第二条,张三,1998-10-10 12:34:32,null),(null,第一条回复 1,李四,1998-10-10 12:35:32,1),(null,第二条回复 1,李四,1998-10-10 12:36:32,2),(null,第一条回复 2,王五,1998-10-10 12:37:32,1),(null,第一条回复 3,李四,1998-10-10 12:38:32,1),(null,第二条回复 2,李四,1998-10-10 12:39:32,2),(null,第一条回复 4,王五,1998-10-10 12

6、:39:40,1);答案:select a.title,a.postuser,(select max(postdate) from articles where parentid=a.id) replyfrom articles a where a.parentid is null;46. 查出比经理薪水还高的员工信息:Drop table if not exists employees;create table employees(id int primary key auto_increment,namevarchar(50),salary int,managerid int refere

7、nces employees(id);insert into employees values (null, lhm,10000,null), (null, zxx,15000,1),(null,flx,9000,1),(null,tg,10000,2),(null,wzg,10000,3);Wzg 大于 flx,lhm 大于 zxx解题思路:根据 sql 语句的查询特点,是逐行进行运算,不可能两行同时参与运算。涉及了员工薪水和经理薪水,所有,一行记录要同时包含两个薪水,所有想到要把这个表自关联组合一下。首先要组合出一个包含有各个员工及该员工的经理信息的长记录,譬如,左半部分是员工,右半部分是

8、经理。而迪卡尔积会组合出很多垃圾信息,先去除这些垃圾信息。select e.* from employees e,employees m where e.managerid=m.id ande.salarym.salary;47. 求出小于 45 岁的各个老师所带的大于 12 岁的学生人数数据库中有 3 个表 teacher 表,student 表,tea_stu 关系表。teacher 表 teaID name agestudent 表 stuID name ageteacher_student 表 teaID stuID要求用一条 sql 查询出这样的结果1)显示的字段要有老师 name,

9、 age 每个老师所带的学生人数SELECT t1.teaID,COUNT(*) FROM teacher_student t1 LEFT JOIN teachert2 ON t1.teaID=t2.teaID GROUP BY t1.teaID2)只列出老师 age 为 40 以下,学生 age 为 12 以上的记录SELECT t1.teaID,t2.name AS teaName,t1.stuID,t3.name ASstuName FROM teacher_student t1 INNER JOIN teacher t2 ONt1.teaID=t2.teaID AND t2.age12

10、48. 求出发帖最多的人:select authorid,count(*) total from articles group by authorid ORDER BYtotal DESC LIMIT 149. 一个用户表中有一个积分字段,假如数据库中有 100 多万个用户,若要在每年第一天凌晨将积分清零,你将考虑什么,你将想什么办法解决?alter table drop column score;alter table add colunm score int;可能会很快,但是需要试验,试验不能拿真实的环境来操刀,并且要注意,这样的操作时无法回滚的,在我的印象中,只有 inert updat

11、e delete 等 DML语句才能回滚,对于 create table,drop table ,alter table 等 DDL 语句是不能回滚。解决方案一,update user set score=0;解决方案二,假设上面的代码要执行好长时间,超出我们的容忍范围,那我就alter table user drop column score;alter table user add column score int。51. xxx 公司的 sql 面试Table EMPLOYEES Structure:EMPLOYEE_ID NUMBER Primary Key,FIRST_NAME VA

12、RCHAR2(25),LAST_NAME VARCHAR2(25),Salary number(8,2),HiredDate DATE,Departmentid number(2)Table Departments Structure:Departmentid number(2) Primary Key,DepartmentName VARCHAR2(25).1)基于上述 EMPLOYEES 表写出查询:写出雇用日期在今年的,或者工资在1000,2000之间的,或者员工姓名(last_name)以Obama打头的所有员工,列出这些员工的全部个人信息。select * from employee

13、swhere Year(hiredDate) = Year(date()or (salary between 1000 and 200)or left(last_name,3)=abc;2) 基于上述 EMPLOYEES 表写出查询:查出部门平均工资大于 1800 元的部门的所有员工,列出这些员工的全部个人信息。mysql select id,name,salary,deptid did from employee1 where (selectavg(salary)from employee1 where deptid = did) 1800;3) 基于上述 EMPLOYEES 表写出查询:查

14、出个人工资高于其所在部门平均工资的员工,列出这些员工的全部个人信息及该员工工资高出部门平均工资百分比。selectemployee1.*,(employee1.salary-t.avgSalary)*100/employee1.salaryfrom employee1,(select deptid,avg(salary) avgSalary from employee1 group by deptid) astwhere employee1.deptid = t.deptid and employee1.salaryt.avgSalary;1、阅读下面这段 CREATE TABLE 代码,该段

15、代码执行失败的原因是()CREATE TABLE orders(ord_no NUMBER(2) CONSTRAINT ord_pk PRIMARY KEY,ord_date DATE,cust_id NUMBER(4);CREATE TABLE ord_items(ord_no NUMBER(2),item_no NUMBER(3),qty NUMBER(3) CHECK (qty BETWEEN 100 AND 200),expiry_date date CHECK (expiry_date SYSDATE),CONSTRAINT it_pk PRIMARY KEY (ord_no,item_no),CONSTRAINT ord_fk FOREIGN KEY(ord_no) REFERENCES orders(ord_no);A. SYSDATE 不能用于 CHECK 约束中。B. BETWEEN 子句不能用于 CHECK 约束中。C. CHECK 约束不能作用在 DATE 类型的列。D. ORD_NO 和 ITEM_NO 不能作为组合主键,因为 ORD_NO 是一个外键。2、关于索引以下哪两个描述是正确的? ()A. 创建索引可以提升表的查询效率B. 可以在表和简单视图上创建索引C. 同一个列只能创建一个索引D. 如果选择了不同的列组合,那么可以使用相同的列创建多个索引

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 工作范文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号