黑马程序员技术交流社区
标题: mysql查询 [打印本页]
作者: qaz1070608974 时间: 2016-4-9 13:08
标题: mysql查询
1.查询所有的商品. select * from product;
2.查询商品名和商品价格. select pname,price from product;
3.别名查询,使用的as关键字,as可以省略的.
3.1表别名: select * from product as p;
3.2列别名:select pname as pn from product;
4.去掉重复值. select distinct price from product;
5.查询结果是表达式(运算查询):将所有商品的价格+10元进行显示.
select pname,price+10 from product;
6.查询商品名称为十三香的商品所有信息:
* select * from product where pname = '十三香';
7.查询商品价格>60元的所有的商品信息:
* select * from product where price > 60;
where后的条件写法:
* > ,<,=,>=,<=,<>
* like 使用占位符 _ 和 % _代表一个字符 %代表任意个字符.
* select * from product where pname like '%新%';
* in在某个范围中获得值.
* select * from product where pid in (2,5,8);
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |