测试那些事儿—SQL server exists子查询
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了测试那些事儿—SQL server exists子查询,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1597字,纯文字阅读大概需要3分钟。
内容图文
![测试那些事儿—SQL server exists子查询](/upload/InfoBanner/zyjiaocheng/508/11617b05d0a34b21b24fcf696859afcb.jpg)
exists子查询
--一次性购买“手机数码”产品的数量超过三个的消费金额打8折
--根据已知项查询未知项
--【1】根据类别名称查询类别编号
select sortid from commoditysort where sortname=‘手机数码‘
--【2】根据类别编号查询商品编号
select commodityid from commodityinfo
where sortid=
(select sortid from commoditysort where sortname=‘手机数码‘)
--【3】根据商品编号去查询订单表中的购买数量超过三个的订单信息
select commodityid from orderinfo
where commodityid in --注意此处为in还是=
(
select commodityid from commodityinfo
where sortid=
(select sortid from commoditysort where sortname=‘手机数码‘))
and amount >3
--【4】购买超过3个的用户的付款金额打8折
if exists(
select commodityid from orderinfo
where commodityid in --注意此处为in还是=
(
select commodityid from commodityinfo
where sortid=
(select sortid from commoditysort where sortname=‘手机数码‘))
and amount >3
)
begin
--对付款金额打8折
update orderinfo set paymoney = paymoney * 0.8
where commodityid in
(
select amount from orderinfo
where commodityid in --注意此处为in还是=
(
select commodityid from commodityinfo
where sortid=
(select sortid from commoditysort where sortname=‘手机数码‘))
and amount >3
)
end
--通常会使用not exists 对子查询结果进行取反
--exists:子查询查到记录,结果为真,否则结果为假
--not exists:子查询查不到结果,结果为真。
测试那些事儿—SQL server exists子查询
标签:upd 超过 select end 技术 数码 image alt width
本文系统来源:https://www.cnblogs.com/mgg520813/p/10935810.html
内容总结
以上是互联网集市为您收集整理的测试那些事儿—SQL server exists子查询全部内容,希望文章能够帮你解决测试那些事儿—SQL server exists子查询所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。