某IT公司招聘试题.doc已知有如下菜单表menu,字段分别为id-菜单编号(主键),name-菜单名称,parentid- 上级菜单编号,operator-录入人,请根据要求写出查询语句
Id
Name
ParentID
Operator
1
家具
0
管理员
2
电器
0
管理员
3
1
管理员
4
1
李明
5
1
管理员
6
电视机
2
管理员
7
电视机
2
李明
8
空调
2
管理员
9
电视机
2
李明
1) 查询录入人为管理员的全部记录,并按菜单名倒序排序
答案:
select * from menu t where t. operator='管理员';
2) 查询管理员录入了多少条记录
答案:
select count (*) from menu t where t. operator=,管理员’;
3) 删除不是由管理员录入的记录
答案:
delete from menu t where t. operator/〉'管理员';
4) 请插入一条记录,菜单名称为微波炉,上级菜单为电器,录入人为管理员
答案:
insert into menu (id, name, parented, operator) values ( '10'微波
炉','2,,,管理员');
5) ,
答案:
update menu t set t. name=, 米床’where t. name=, 米床';
6) 请创建一张表名为new_menu的表,字段与表menu 一致,其中字段id为主键,字段 id和字段parentid的数据类型为长整数且不为空,其它字段的数据类型都是字符 串,长度50,可为空
答案:
create table new menu
id int not null,
name char(50),
parentid not null,
operator char(50),
primary key(id)
);
请在表new_menu增加一个字段,字段名称为create_date,数据类型为日期类型 答案:
alter table new_menu add column create_date date;
请把表new_menu新增的字段create_date删除
答案:
alter table new_menu drop column create_date;
请将表menu的全部记录复制到表new_menu
答案:
insert into new_menu (id, name, parentid, operator) (select
t. id, t. name, t. parent id, t. operator from menu t);
请将表new_menu删除
答案:
drop table new_menu;
ID 假设表menu中的数据即为题目中所列(以下其它题目同样以此为条件),请写出 一条sql语句,查询出菜单编号,菜单名称,以及当前菜单的上级菜单名称 答案:以下两种中的任一种都可以
se
某IT公司招聘试题 来自淘豆网m.daumloan.com转载请标明出处.