【sql in excel】入门17:补漏(and、or).docx

上传人:b****9 文档编号:50053 上传时间:2022-10-01 格式:DOCX 页数:6 大小:140.62KB
下载 相关 举报
【sql in excel】入门17:补漏(and、or).docx_第1页
第1页 / 共6页
【sql in excel】入门17:补漏(and、or).docx_第2页
第2页 / 共6页
【sql in excel】入门17:补漏(and、or).docx_第3页
第3页 / 共6页
【sql in excel】入门17:补漏(and、or).docx_第4页
第4页 / 共6页
【sql in excel】入门17:补漏(and、or).docx_第5页
第5页 / 共6页
点击查看更多>>
下载资源
资源描述

【sql in excel】入门17:补漏(and、or).docx

《【sql in excel】入门17:补漏(and、or).docx》由会员分享,可在线阅读,更多相关《【sql in excel】入门17:补漏(and、or).docx(6页珍藏版)》请在冰豆网上搜索。

【sql in excel】入门17:补漏(and、or).docx

【sqlinexcel】入门17:

补漏(and、or)

1、求金额小于等于200或金额大于等于500的数据。

select*from[Sheet1$]where金额<=200or金额>=500

结果:

上面的sql语句不能写为:

select*from[Sheet1$]where金额<=200or金额>=500

结果:

没有数据

虽然and可以配合where使用多个条件,但对于同一个字段的,要分清楚条件的关系。

将上述语句改为:

select*from[Sheet1$]where金额>=200and金额<=500

结果:

上述sql语句写为:

select*from[Sheet1$]where金额>=200or金额<=500

结果:

or连接的条件,只要有一个true,就能返回结果。

而and则需要每个条件都满足。

下面的sql语句将返回没有结果:

select*from[Sheet1$]where姓名='A'and姓名='B'

如改为:

select*from[Sheet1$]where姓名='A'or姓名='B'

结果:

andor结合使用。

sql语句:

select*from[Sheet1$] where姓名='A'  and 金额<=200 or 金额>=500

结果:

这样看sql语句,或许有困惑。

改写为下面的格式:

select*from[Sheet1$]

 where姓名='A' 

and 

(金额<=200)

 or 

(金额>=500)

这个语句分为两个条件,

第一个条件为蓝色语句,姓名A,且金额<=200,运行语句

select*from[Sheet1$]

 where姓名='A' 

and 

(金额<=200)

结果为:

第二个条件为红色语句,金额>=500的数据,运行语句

select*from[Sheet1$]where (金额>=500)

结果为:

两者结合在一起,得出第一次的结果:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1