一道笔试题,求完整答案,在线等
假设有关系数据库表A:(工号,姓名,证件号码,性别,年龄,工资),合法证件号码表B(证件号码,签发机关),请编程抽取该表中工资>5000且年龄<25的记录,对抽取的每条记录,检查其证件号码是否合法,如果合法的,请将记录写入表C,C的结构和A相同。请用游标和嵌入SQL实现。 (ps:小弟完全不懂,求完整答案自己琢磨)
[解决办法]
- SQL code
insert into c select * from a where 工资>5000 and 年龄<25 and exists(select 1 from b where 证件号码=a.证件号码)
[解决办法]
- SQL code
insert cselect * from a join b on a.证件号码=b.证件号码where a.工资>5000 and a.年龄<25
[解决办法]
- SQL code
insert into Cselect * from A a where [工资]>5000 and [年龄] <25 and exists (select 1 from B b where a.[证件号码] = b.[证件号码])
[解决办法]
- SQL code
INSERT INTO C(工号,姓名,证件号码,性别,年龄,工资)SELECT * FROM A WHERE 工资 > 5000 AND 年龄 < 25 AND EXISTS(SELECT 1 FROM B WHERE A.证件号码 = B.证件号码)
[解决办法]
如果C表不存在的,使用以下语句
- SQL code
select * into C from a join b on a.证件号码=b.证件号码where a.工资>5000 and a.年龄<25
我的异常网推荐解决方案:软件开发者薪资,http://www.myexception.cn/other/1391128.html