把一些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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。