MYSQL谓词的使用和表达式

in//使用IN谓词将一个值与其他几个值进行比较

select * from users where id in(1,2,5);相当于select * from users where id=1 or id=2 or id=5;

between//将单一值与一个范围内的值比较

select * from users where id between 2 and 4;相当于select * from users where id>=2 and id<=4;

like//搜索具有某些模式的字符串。通过百分号和下划线指定模式。

exists//测试某个条件的行的存在性

表达式>ALL//表达式大于由全查询返回的每个单值

表达式>ANY//表达式至少大于由全查询返回的值之一

条件表达式:

select id,case name
when '高某' then 'gp'
when '曹某' then 'cw'
when '唐某' then 'tg'
else 'wz'
end as nname
from users;

嵌套表表达式:

select id,name,gender,birthday,address
from(
select id,name,gender,birthday,address from users where address='北京'
)as newusers
where id<3;

posted @ 2018-04-18 17:41  第五  阅读(326)  评论(0编辑  收藏  举报