请求这个sql如何写

[复制链接]
查看11 | 回复5 | 2013-8-26 10:08:51 | 显示全部楼层 |阅读模式


72B9.tm.png (66.59 KB, 下载次数: 5)
下载附件
2016-5-10 16:54 上传

答案是A,但写不出来,

回复

使用道具 举报

千问 | 2013-8-26 10:08:51 | 显示全部楼层
本帖最后由 〇〇 于 2016-5-10 18:52 编辑
就是条件insert
merge能代替上面的操作
回复

使用道具 举报

千问 | 2013-8-26 10:08:51 | 显示全部楼层
insert into b select emp.id,emp.sal*case when exists(select 1 from order where order.repid=emp.id)then 1.02 else 1.01 end from emp where sal 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000);
SELECT * FROM bonuses ORDER BY employee_id;
EMPLOYEE_IDBONUS
----------- ----------
153180
154175
155170
159180
160175
161170
179620
173610
165680
166640
164720
172730
167620
171740

回复

使用道具 举报

千问 | 2013-8-26 10:08:51 | 显示全部楼层
http://www.itpub.net/forum.php?m ... =1937683&page=1
搜到这个,既要往bonuses里插入,又要更新employees表,貌似一条语句做不到。
回复

使用道具 举报

千问 | 2013-8-26 10:08:51 | 显示全部楼层
〇〇 发表于 2016-5-11 09:14
文档原文,备用
Examples

楼主原题中还有这样的要求:
“Those who have made sales get a bonus of 1% of their salary and also a salary increase of 1%."
而我的理解,工资的增加,要修改EMPLOYEES表中相应的SALARY列才可以。如果是这样,要一条语句同时修改BONUSES表和EMPLOYEES表,不能吧?

回复

使用道具 举报

千问 | 2013-8-26 10:08:51 | 显示全部楼层
bfc99 发表于 2016-5-11 16:51
楼主原题中还有这样的要求:
“Those who have made sales get a bonus of 1% of their salary and also ...

感觉这个题目有问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行