MySQL从入门到精通-查询数据
查询数据
SELECT * FROM sheet1$; -- 查询所有字段
SELECT 序号1,业务类型,英文品名,数量,货物件数,计费重量,负责人 FROM sheet1$;--查询指定字段
SELECT * FROM sheet1$ WHERE id1=1;-- WHERE 条件查询
SELECT * FROM sheet1$ WHERE plt>10;
SELECT * FROM sheet1$ WHERE plt IN (11,13);-- in 查询
SELECT * FROM sheet1$ WHERE plt BETWEEN 7 AND 15;
SELECT * FROM sheet1$ WHERE response LIKE '小强'; -- LIKE模糊查询
SELECT * FROM sheet1$ WHERE response LIKE '小强%';
SELECT * FROM sheet1$ WHERE response LIKE '%小强%';
SELECT * FROM sheet1$ WHERE response LIKE '小强_';
SELECT * FROM sheet1$ WHERE plt IS NULL; -- 空值查询
SELECT * FROM sheet1$ WHERE plt>15 AND response LIKE '%小强%'; -- 带AND多条件查询(同时满足条件)
SELECT * FROM sheet1$ WHERE plt>15 OR response LIKE '%小强%'; -- 带OR多条件查询(满足一个条件)
SELECT DISTINCT NAME FROM sheet1$; -- 去重复查询
SELECT * FROM sheet1$ ORDER BY plt,charge DESC; -- ORDER BY 排序,默认为升序,DESC关键字降序
SELECT TYPE,GROUP_CONCAT(response) FROM sheet1$ GROUP BY TYPE ;-- GROUP BY 查询
SELECT TYPE,COUNT(response) FROM sheet1$ GROUP BY TYPE ;
SELECT TYPE,COUNT(response) FROM sheet1$ GROUP BY TYPE HAVING COUNT(response)>5 ;-- HAVING限制分组输出条件
SELECT TYPE,COUNT(response) FROM sheet1$ GROUP BY TYPE WITH ROLLUP;-- WITH ROLLUP 输出总计
SELECT * FROM sheet1$ LIMIT 0,5;-- LIMIT分页查询
SELECT * FROM sheet1$ LIMIT 5,10;