1.数据表的查询操作
1.简单查询
查询所有货品的id,productName,salePrice
SELECT id,productName,salePrice from product
1.1.消除结果中重复的数据。只对某一列有效 DISTINCT
需求: 查询商品的分类编号。
SELECT DISTINCT dir_id FROM product
1.2实现数学运算
SELECT 5*7
1.3.设置列名的别名
select department dept from emp where id=?
1.4.设置显示格式:
需求:查询商品的名字和零售价。
格式:xxx商品的零售价为:xxx
SELECT CONCAT(productName,"商品的零售价为:",salePrice) intro FROM product
2.条件查询
select * from 表名where 条件内容
from --- > where ---> select
2.2逻辑运算
SELECT xxx FROM 表名WHERE 条件1 (and,or,not) 条件2
2.3.范围查询-BETWEEN AND
选择id,货品名称,批发价在300-400之间的货品
SELECT id,productName,salePrice*cutoff FROM product WHERE salePrice*cutoff BETWEEN 300 and 400
2.4.集合查询- IN
选择id,货品名称,分类编号为2,4的所有货品
SELECT id,productName,dir_id FROM product where dir_id in(2