java面试题06
题目:
数据库
1、 表名:g_cardapply
字段(字段名/类型/长度):
g_applyno varchar 8;//申请单号(关键字)
g_applydate bigint 8;//申请日期
g_state varchar 2;//申请状态
2、 表名:g_cardapplydetail
字段(字段名/类型/长度):
g_applyno varchar 8;//申请单号(关键字)
g_name varchar 30;//申请人姓名
g_idcard varchar 18;//申请人身份证号
g_state varchar 2;//申请状态
其中,两个表的关联字段为申请单号。
01、 查询身份证号码为440401430103082的申请日期
02、 查询同一个身份证号码有两条以上记录的身份证号码及记录个数
03、 将身份证号码为440401430103082的记录在两个表中的申请状态均改为07
04.从表g_cardapplydetail中删除姓李的记录
创建数据库和数据表
CREATE DATABASE IF NOT EXISTS exam
USE exam
CREATE TABLE IF NOT EXISTS g_cardapply(
g_applyno INT(8) PRIMARY KEY NOT NULL AUTO_INCREMENT COMMENT '申请单号',
g_applydate DATE COMMENT '申请日期',
g_state VARCHAR(2) COMMENT '申请状态'
)CHARSET='utf8' ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS g_cardapplydetail(
g_applyno INT(8) NOT NULL COMMENT '申请单号',
g_name VARCHAR(20) COMMENT '申请人姓名',
g_idcard VARCHAR(20) COMMENT '申请人身份证号',
g_state VARCHAR(10) COMMENT '申请状态'
)CHARSET='utf8' ENGINE=INNODB;
ALTER TABLE g_cardapplydetail ADD CONSTRAINT foreign_cardapplydetail_cardapply FOREIGN KEY (g_applyno) REFERENCES g_cardapply (g_applyno)
INSERT INTO g_cardapply VALUES(1,'2017-10-22',0);
INSERT INTO g_cardapply VALUES(2,'2017-10-23',1);
INSERT INTO g_cardapply VALUES(3,'2017-10-25',1);
INSERT INTO g_cardapply VALUES(4,'2017-10-27',0);
INSERT INTO g_cardapply VALUES(5,'2017-10-28',1);
INSERT INTO g_cardapply VALUES(6,'2017-10-21',1);
INSERT INTO g_cardapplydetail VALUES(1,'xiaohei1','11111111',0);
INSERT INTO g_cardapplydetail VALUES(2,'xiaohei2','22222222',1);
INSERT INTO g_cardapplydetail VALUES(3,'xiaohei3','33333333',1);
INSERT INTO g_cardapplydetail VALUES(4,'xiaohei4','44444444',0);
INSERT INTO g_cardapplydetail VALUES(5,'xiaohei2','22222222',1);
INSERT INTO g_cardapplydetail VALUES(6,'xiaohei3','33333333',1);
01.SELECT g_applydate FROM g_cardapply a ,g_cardapplydetail d WHERE g_idcard='22222222' AND a.g_applyno=d.g_applyno
02.SELECT g_idcard,COUNT(g_idcard) FROM g_cardapplydetailGROUP BY g_idcard HAVING COUNT(g_idcard)>=2
03.#关闭事务自动提交
SET autocommit=0;
BEGIN;
UPDATE g_cardapply SET g_state='08' WHERE g_applyno IN
(
SELECT g_applyno FROM g_cardapplydetail WHERE g_idcard='22222222'
);
UPDATE g_cardapplydetail SET g_state='08' WHERE g_idcard='22222222';
#rollback;
COMMIT;
#再设置成自动提交
SET autocommit=1;
04..DELETE FROM g_cardapplydetail WHERE g_name LIKE '李%'