共计 985 个字符,预计需要花费 3 分钟才能阅读完成。
把一些 mysql 的罕用语法进行下汇总
1. 简略语句
/*websites 表名 NAME alexa url country 字段 */
SELECT * FROM websites; /* 查问表所有数据 */
SELECT NAME FROM websites; /* 查问表字段数据 */
SELECT * FROM websites where name = "广西"; /* 查问表字段下条件数据 */
SELECT * from websites where name like "_o%"; /* 含糊查问表下数据 */
SELECT * FROM websites where id BETWEEN "1" AND "5"; /* 查问表下字段范畴数据 */
SELECT * FROM websites WHERE name in ("广西","百度"); /* 查问表字段下固定条件数据 */
SELECT DISTINCT country FROM Websites; /* 查问去重值 */
SELECT * FROM Websites WHERE country = "CN" AND alexa > 50; /* 查问表下范畴条件数据 */
SELECT * FROM Websites WHERE country = "USA" OR country="sh"; /* 查问表下条件不同值 */
SELECT * FROM Websites ORDER BY alexa; /* 查问表下值排序后果 */
SELECT * FROM Websites ORDER BY alexa DESC; /* 查问表下排序后果降序 */
SELECT * FROM Websites LIMIT 2; /* 查问表下范畴数据 */
SELECT name as zzz from websites; /* 别名查问表下数据 */
2. 分页
select _column,_column from _table [where Clause] [limit N][offset M]
select *
: 返回所有记录 limit N
: 返回 N 条记录offset M
: 跳过 M 条记录, 默认 M=0, 独自应用仿佛不起作用limit N,M
: 相当于 limit M offset N , 从第 N 条记录开始, 返回 M 条记录
实现分页:
select * from _table limit (page_number-1)*lines_perpage, lines_perpage
或
select * from _table limit lines_perpage offset (page_number-1)*lines_perpage
正文完