1. 程式人生 > >Mysql資料庫-使用的查詢語句大全

Mysql資料庫-使用的查詢語句大全

常規查詢

  1. 查詢所有欄位:select * from 表名;
  2. 查詢指定欄位:select 列1,列2,... from 表名;
  3. 使用 as 給欄位起別名: select 欄位 as 名字.... from 表名;
  4. 查詢某個表的某個欄位:select 表名.欄位 .... from 表名;
  5. 可以通過 as 給表起別名: select 別名.欄位 .... from 表名 as 別名;
  6. 消除重複行: distinct 欄位
    在這裡插入圖片描述

條件查詢

㈠比較運算子:>, <, >=, <=, =, !=, <>

在這裡插入圖片描述

㈡邏輯運算子:and, or, not

在這裡插入圖片描述

㈢模糊查詢:like, rlike

在這裡插入圖片描述

㈣範圍查詢:in,not in,between…and,not between…and

在這裡插入圖片描述
空判斷
在這裡插入圖片描述

排序:order_by

在這裡插入圖片描述

聚合函式:count(), max(), min(), sum(), avg(), round()

在這裡插入圖片描述

分組:group_by, group_concat():查詢內容, having

在這裡插入圖片描述

分頁: limit

在這裡插入圖片描述

連線查詢 :inner join, left join, right join

在這裡插入圖片描述

自關聯:參考省級聯動

在這裡插入圖片描述