Mysql 常用SQL語句集錦

2021-09-25 23:44:15 字數 1236 閱讀 5074

查詢時間,友好提示

乙個sql 返回多個總數

$sql = "select count(*) all, " ;

$sql .= " count(case when status = 1 then status end) status_1_num, ";

$sql .= " count(case when status = 2 then status end) status_2_num ";

$sql .= " from table_name";

update join / delete join

$sql = "update table_name_1 ";

$sql .= " inner join table_name_2 on table_name_1.id = table_name_2.uid ";

$sql .= " inner join table_name_3 on table_name_3.id = table_name_1.tid ";

$sql .= " set *** = *** ";

$sql .= " where *** ";

//delete join 同上。

替換某字段的內容的語句

$sql = "update table_name set content = replace(content, 'aaa', 'bbb') ";

$sql .= " where (content like '%aaa%')";

獲取表中某欄位包含某字串的資料

$sql = "select * from `表名` where locate('關鍵字', 欄位名) ";

查詢表中多餘的重覆記錄

刪除表中多餘的重覆記錄(留id最小)

thanks ~ 

mysql 語句 集錦 mysql常用語句集錦

mysql unix時間戳與日期的相互轉換 unix時間戳轉換為日期用函式 from unixtime select from unixtime 1156219870 日期轉換為unix時間戳用函式 unix timestamp select unix timestamp 2006 11 04 12...

SQL語句集錦

use tablename 要操作的資料庫名 select logicalfilename tablename log 日誌檔名 maxminutes 10,limit on time allowed to wrap log.newsize 1 你想設定的日誌檔案的大小 m setup initia...

mysql常用語句集錦

自 http blog.tom.com zhiming4350 article 2141.html mysql常用語句 在xp下啟動mysql服務命令 net start mysql 關閉命令 net stop mysql mysql安裝目錄 d mysql 進入命令列輸入視窗 dos命令輸入,ro...