oracle case when 查詢各個部門不同工資階段的人數
select d.deptName,e.level1,e.level2,e.level3 from (select deptId,count(case when wage < 5000 then 1 else null end ) level1,count(case when wage >=5000 and wage <15000 then 1 else null end ) level2, count(case when wage > 15000 then 1 else null end ) level3 from t_employee group by deptId) e left join t_dept d on e.deptId = d.deptId
最近一好友問我假設有兩個表。一個是employee表,記錄這員工的基本資訊包括工資、部門id等,另一張表是dept表,記錄這部門的相關資訊。如何通過這兩張表,來查詢出各個部門不同工資階段的人數呢?
經過查詢相關資料,終於寫出這個sql語句,經除錯,能達到要求。本人小白,大佬不知道哪位大佬有效率更高更簡便的寫法呀。歡迎指點。
相關推薦
oracle case when 查詢各個部門不同工資階段的人數
select d.deptName,e.level1,e.level2,e.level3 from (select deptId,count(case when wage < 5000 then 1 else null end ) level1,count(case w
列出各個部門中工資高於本部門的平均工資的員工數和部門號,並按部門號排序(用sql語句來表達)。
AR 思路 進行 info family order size table ID 查詢出各個部門中工資高於本部門的平均工資的員工數和部門號,並按部門號排序(用sql語句來表達) 1.創建的表格 2.思路: (1)首先查詢各個部門的平均工資 1 select dept
查詢每個部門的工資最高的同事的姓名,及工資是多少
spa order color inner group style 查詢 class tno 1 select t1.empno, t1.ename, t1.deptno, t1.sal 2 from emp t1 3 inner join ( 4 select
資料庫SQL實戰3:查詢各個部門當前領導當前薪水詳情以及其對應部門編號dept_no
思想: 題目要求查詢各個部門當前領導當前薪水詳情以及其對應部門編號dept_no。首先根據當前領導通過條件d.to_date = '9999-01-01'進行篩選,然後當前薪水通過條件s.to_date = '9999-01-01'進行再次篩選,最後根據領導的編號通過條件d.emp_no = s
牛客:資料庫實戰—2—查詢各個部門當前(to_date='9999-01-01')領導當前薪水詳情以及其對應部門編號dept_no
CREATE TABLE `dept_manager` ( `dept_no` char(4) NOT NULL, `emp_no` int(11) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (
列出各個部門中工資高於本部門的平均工資的員工數和部門號
列出各個部門中工資高於本部門的平均工資的員工數和部門號,並按部門號排序。用SQL語句詳細介紹一下 採納率:51%11級2013.11.17 select a.deptno,count(*) from emp as a, (select deptno,avg(sal) as avgsal fr
資料庫SQL實戰 --3.查詢各個部門當前領導當前薪水詳情以及其對應部門編號
題目描述 查詢各個部門當前(to_date=‘9999-01-01’)領導當前薪水詳情以及其對應部門編號dept_no CREATE TABLE `dept_manager` ( `dept_no` char(4) NOT NULL, `emp_no` int(
查詢各個部門當前(to_date='9999-01-01')領導當前薪水詳情以及其對應部門編號dept_no之SQL實現
題目描述 查詢各個部門當前(to_date='9999-01-01')領導當前薪水詳情以及其對應部門編號dept_no CREATE TABLE `dept_manager` ( `dept_no` char(4) NOT NULL, `emp_no` int(11) NOT NUL
Oracle CASE WHEN 用法
case when 語法 select t.* , case (selectcolumn) when expression1 then result1 when expression2 then result2 ... when expressionN then resultN e
Oracle case when 實現資料欄位資料的判斷過濾
需求 現在有一份管線資料,表中含有欄位buildTime說明了管線的建設日期,我們需要按時間段統計管線的資料 這是,我們需要對管線表中建設日期所對應的欄位進行分類 實現如下: 實現 對現有的資料進行分類判斷過濾,使用到了 case when ca
Oracle Case When巢狀判斷結果集SQL
資料需求:此SQL是判斷UPS狀態使用1、一個機房有兩個UPS2、當其中一個UPS出現問題時,此時機房的UPS告警狀態為0,否則為13、UPS狀態0異常,1正常4、請編寫一個機房為例子 UPS編碼為:
Oracle CASE WHEN 用法介紹
1. CASE WHEN 表示式有兩種形式 --簡單Case函式 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜尋函式 CASE WHEN sex = '1
轉 ORACLE CASE WHEN 及 SELECT CASE WHEN的用法
四,根據條件有選擇的UPDATE。 例,有如下更新條件 工資5000以上的職員,工資減少10%工資在2000到4600之間的職員,工資增加15% 很容易考慮的是選擇執行兩次UPDATE語句,如下所示--條件1 UPDATE Personnel SET salary = salary * 0.9 WH
oracle case when 使用
1. CASE WHEN 表示式有兩種形式 --簡單Case函式 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜尋函式 CASE WHEN sex = '1' THEN '男' WHEN
oracle case when then else end用法
語法: CASE search_expression 當表達1那麼結果1 當表達2那麼結果2 比如客戶型別個人0,機構1,產品2對應的證件型別分別對應1018,1019,1355字典項。 下面舉例說明具體實現:如何把某客戶型別對應的證件型別翻譯成中文
ORACLE CASE WHEN 及 SELECT CASE WHEN的用法
CASE 語句CASE selector WHEN value1 THEN action1; WHEN value2 THEN action2; WHEN value3 THEN action3; ….. ELSE actionN;END CASE; CA
【Oracle】高速查詢資料庫庫中工資最高的10條使用者記錄;
高速查詢資料庫庫中工資最高的10條使用者記錄; 1、查詢所有的使用者記錄 select * from user order by wage desc; 2、因為獲取所有的欄位太耗時,我們這裡只取每條記錄的實體地址——rowid; select r
MySQL條件表示式case when查詢
先建立一張這樣的一張表user表 再建立一張成績表 需求是查詢到學生各科的成績,並劃分級別。成績大於等於60小於80屬於及格,成績大於80優秀,小於60為不及格 select u.u
oracle case when的使用和將列連線成字串
select a.*,b.name as appname, (case a.dbsrctype when 1 then (select serverIp||':'||port||','||userna
oracle case when的使用方法
http://www.2cto.com/database/201205/130090.html 大家都知道Case when的用法,一旦滿足了某一個WHEN ,則這一條資料就會退出CASE WHEN,而不再考慮其他CASE ,文章來詳細的介紹了case when的用法並舉例