Mysql_DQL01(条件查询)

Mysql_DQL

一、查询所有

select * from 表名;

二、指定查询

		select 字段名 from 表名;
		select * from 表名 where 字段 =  ;
		-- 价格不等于60
			select * from 表名 where price!=60;
			select * from 表名 where price<>60;
			select * from 表名 where not(price=60);
		--价格在200-1000之间
			select * from 表名 where price between 200 and 1000;
			select * from 表名 where price > 200 and price <1000;
			select * from 表名 where price > 200 && price <1000;
		--价格是200或800
			select * from 表名 where price in(200,800);
			select * from 表名 where price > 200 or price <1000;
			select * from 表名 where price > 200 || price <1000;
		--含有'裤'字
			select * from 表名 where 字段 like '%裤%';	--%用来匹配任意字符
		--以'裤'开头
			select * from 表名 where 字段 like '裤%';	
		--第二个字为'裤'字
			select * from 表名 where 字段 like '_裤%';	
		--查询字段为null
			select * from 表名 where 字段 is null;
		--使用least求最小值
			least(10,20) as small;	--如果有null,结果为null
		--使用greatest求最大值
			greatest(10,20) as big_number; --含null结果为null

三、表别名(关键字 as 可省略)

	select p.字段 from 表名 p;
	--列别名
	select pname as '商品名',price '商品价格' from 表名;
	--去掉重复值
	select distinct 字段 from 表名;
	select distinct * from 表名;
	--运算查询:将指定字段+10
	select 字段+10 p from 表名;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值