Mysql排序查詢

2021-10-18 03:24:48 字數 895 閱讀 6804

select 查詢列表

from 表

where 篩選條件

order by 排序列表 (asc or desc,預設公升序)

select *

from employees

order by salary asc, employee_id desc;

1.查詢員工的姓名和部門號和年薪,按年薪降序,按姓名公升序

select last_name,department_id,salary12(1+ifnull(commission_pct,0)) as 年薪

from employees

order by 年薪 desc, last_name asc;

2.選擇工資不在8000到17000的員工姓名和工資,按工資降序

select last_name,salary

from employees

where not(salary between 8000 and 17000)

order by salary desc;

3.查詢郵箱中包含e的員工資訊,並先按照郵箱的位元組數降序,再按部門號公升序

select *,length(email)

from employees

where email like 『%e%』

order by length(email) desc, department_id asc;

「花花世界,靜守己心」

小徐加油!

----2021.1.28

mysql查詢字段排序 mysql 排序查詢字段

mysql 排序查詢字段 閱讀 504 排序查詢 語法 select 查詢欄位1 from 表 where 篩選條件 order by 要排序欄位2 asc公升序 desc 降序,要排字段3 asc公升序 desc降序 如果不寫預設為公升序 案例 查詢員工資訊,要求工資從高到低排序 select f...

mysql 排序查詢

高階3 排序查詢 語法 select 要查的字段 from 表名 where 條件 order by 排序列表 asc desc asc 表示公升序,desc表示降序 order by 可以支援單個字段,多個字段,函式,表示式,別名。案例 查詢員工工資從高到低排列的員工資訊 select from ...

MySQL 查詢排序

為了方便檢視資料,可以對資料進行排序 語法 select from 表名 order by 列1 asc desc 列2 asc desc,說明 將行資料按照列1進行排序,如果某些行列1的值相同時,則按照列2排序,以此類推 預設按照列值從小到大排列 asc asc從小到大排列,即公升序 desc從大...