1、查询
SELECT * FROM 表名 WHERE 条件;
(1)、SELECT * FROM 表名; #查询表内的所有数据
SELECT * FROM PRODUCT;
(2)、SELECT 字段1,字段2... FROM 表名; #查询表内的指定字段的数据
SELECT PIN,PRICE FROM PRODUCT;
(3)、SELECT * FROM 表名 AS 别名; #表别名查询
SELECT * FROM PRODUCT AS p;
(4)、SELETE 字段名 AS 别名,字段名 AS 别名...FROM 表名; #字段别名查询,并显示别名
SELECT PID AS '编号',PNAME AS '品牌' FROM PRODUCT;
(5)、SELECT DISTINCT 字段 FROM 表名; #查询指定字段并去除重复值
SELECT DISTINCT CATEGORY_ID FROM PRODUCT;
(6)、SELECT 字段+值 FROM 表名; #运算查询:查询指定字段并给该字段进行运算
SELECT PRICE+10 FROM PRODUCT;
(7)、SELECT * FROM 表名 WHERE 条件; #查询符合条件的所有字段
SELECT * FROM PRODUCT WHERE PNAME='花花公子'; #查询PNAME是花花公子的所有product信息
SELECT * FROM PRODUCT WHERE PRICE=800; #查询PRICE是800的所有product信息
SELECT * FROM PRODUCT WHERE PRICR!=800; #查询price不是800的所有product信息
SELECT * FROM PRODUCT WHERE NOT(PRICE=800); #同上
SELETE * FROM PRODUCT WHERE PRICE<>800; #同上
SELECT * FROM PRODUCT WHERE PRICE>60; #查询price大于60的所有product信息
SELECT * FROM PRODUCT WHERE PRICE BETWEEN 200 AND 1000; #查询price在200到1000之间的所有product信息
SELECT * FROM PRODUCT WHERE PRICR>=200 AND PRICE<=1000; #同上
SELECT * FROM PRODUCT WHERE PRICE=200 OR PRICE=800; #查询price是200或是800的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '%霸%'; #查询pname中包含‘霸’的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '香%'; #查询pname中以‘香’开头的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '_想%'; #查询pname中第二个字是‘想’的所有product信息
SELECT * FROM PRODUCT WHERE CATEGORY_ID IS NULL; #查询category_id为空的所有product信息
SELECT * FROM PRODUCT WHERE CATEGORY_ID IS NOT NULL; #查询category_id不为空的所有product信息
(8)、SELECT * FROM 表名 ORDER BY 字段 ASC|DESC; #查询表内所有信息并按指定字段进行排序(ASC:升序、DESC:降序),排序默认升序(ASC)
SELECT * FROM PRODUCT ORDER BY PRICE DESC; #查询表内所有信息并按price字段进行降序排列
SELECT * FROM 表名 WHERE 条件;
(1)、SELECT * FROM 表名; #查询表内的所有数据
SELECT * FROM PRODUCT;
(2)、SELECT 字段1,字段2... FROM 表名; #查询表内的指定字段的数据
SELECT PIN,PRICE FROM PRODUCT;
(3)、SELECT * FROM 表名 AS 别名; #表别名查询
SELECT * FROM PRODUCT AS p;
(4)、SELETE 字段名 AS 别名,字段名 AS 别名...FROM 表名; #字段别名查询,并显示别名
SELECT PID AS '编号',PNAME AS '品牌' FROM PRODUCT;
(5)、SELECT DISTINCT 字段 FROM 表名; #查询指定字段并去除重复值
SELECT DISTINCT CATEGORY_ID FROM PRODUCT;
(6)、SELECT 字段+值 FROM 表名; #运算查询:查询指定字段并给该字段进行运算
SELECT PRICE+10 FROM PRODUCT;
(7)、SELECT * FROM 表名 WHERE 条件; #查询符合条件的所有字段
SELECT * FROM PRODUCT WHERE PNAME='花花公子'; #查询PNAME是花花公子的所有product信息
SELECT * FROM PRODUCT WHERE PRICE=800; #查询PRICE是800的所有product信息
SELECT * FROM PRODUCT WHERE PRICR!=800; #查询price不是800的所有product信息
SELECT * FROM PRODUCT WHERE NOT(PRICE=800); #同上
SELETE * FROM PRODUCT WHERE PRICE<>800; #同上
SELECT * FROM PRODUCT WHERE PRICE>60; #查询price大于60的所有product信息
SELECT * FROM PRODUCT WHERE PRICE BETWEEN 200 AND 1000; #查询price在200到1000之间的所有product信息
SELECT * FROM PRODUCT WHERE PRICR>=200 AND PRICE<=1000; #同上
SELECT * FROM PRODUCT WHERE PRICE=200 OR PRICE=800; #查询price是200或是800的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '%霸%'; #查询pname中包含‘霸’的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '香%'; #查询pname中以‘香’开头的所有product信息
SELECT * FROM PRODUCT WHERE PNAME LIKE '_想%'; #查询pname中第二个字是‘想’的所有product信息
SELECT * FROM PRODUCT WHERE CATEGORY_ID IS NULL; #查询category_id为空的所有product信息
SELECT * FROM PRODUCT WHERE CATEGORY_ID IS NOT NULL; #查询category_id不为空的所有product信息
(8)、SELECT * FROM 表名 ORDER BY 字段 ASC|DESC; #查询表内所有信息并按指定字段进行排序(ASC:升序、DESC:降序),排序默认升序(ASC)
SELECT * FROM PRODUCT ORDER BY PRICE DESC; #查询表内所有信息并按price字段进行降序排列
SELECT * FROM PRODUCT ORDER BY PRICE DESC,CATEGORY_ID DESC; #查询表内所有信息在price降序排列的基础上再对category_id进行降序排列
互相学习,有错请指教!