码迷,mamicode.com
首页 > 其他好文 > 详细

7_查询之where

时间:2015-05-20 18:45:42      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:having   where   between   


查询

条件判断


select 5种子句:

where 条件查询

group by 分组

having 筛选

order by 排序

limit 限制结果条数


---------------------


where


1.运算符: 

<=

=

!=  <>不等于有两种表示

>=

>

inin (4,5)

betweenbetween 2000 and 3000

取出goods_id是4和5的商品:

select goods_id,goods_name from goods where goods_id in (4,5);


取出goods_price是2000到3000之间的商品:

select goods_price,goods_name from goods where goods_price between 2000 and 3000;


2.逻辑运算符

not 或 !

or  或 ||

and 或 &&


取出goods_price是2000到3000之间的商品,和goods_price是500-1000之间的商品:

select goods_name,goods_price from goods 

where goods_price >=2000 and goods_price<=3000 or goods_price >=500 and goods_price <=1000;




3.模糊查询

like "诺基亚%"%是通配任意字符

like "诺基亚N__"_是单个字符

取出所有"诺基亚"开头的商品:

select goods_id,goods_name from goods where goods_name like "诺基亚%";


取出所有"诺基亚NXX"开头的,N后面有两个字符的商品:

select goods_id,goods_name from goods where goods_name like "诺基亚N__";



7_查询之where

标签:having   where   between   

原文地址:http://1154179272.blog.51cto.com/10217799/1653229

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!