把一些mysql的经常使用语法进行下汇总mysql
/*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; /*别名查询表下数据*/
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 条记录
实现分页:web
select * from _table limit (page_number-1)*lines_perpage, lines_perpage 或 select * from _table limit lines_perpage offset (page_number-1)*lines_perpage