把一些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