mysql子查詢習題98

2022-09-19 20:39:09 字數 3572 閱讀 1377

1 #1

.查詢工資最低的員工資訊:last name, salary

2select

3last_name,

4salary

5from

6employees

7where

8 salary =(9

select

10min

(salary)

11from

12employees

13);

1415 #2

.查詢平均工資最低的部門資訊

16select17*

18from

19departments

20where

21 department_id =(22

select

23department_id

24from

25employees

26group

by27

department_id

28order

by29

**g(salary)

30 limit 1

31);

3233 #3

.查詢平均工資最低的部門資訊和該部門的平均工資

34#①各部門的平均工資

35select

36**g

(salary),

37department_id

38from

39employees

40group

by41

department_id #②求出最低平均工資的部門編號

42select

43**g

(salary),

44department_id

45from

46employees

47group

by48

department_id

49order

by50

**g(salary)

51 limit 1;52

53#③查詢部門資訊

54select

55 d.*

, ag

56from

57departments d

58join(59

select

60**g

(salary),

61department_id

62from

63employees

64group

by65

department_id

66order

by67

**g(salary)

68 limit 1

69 ) ag_dep on d.department_id = ag_dep.department_id #4

.查詢平均工資最高的job資訊

70select

71**g

(salary)

72from

73employees

74group

by75

job_id

76order

by77

**g(salary) desc

78 limit 1 ②查詢job資訊 select79*

80from

81jobs

82where

83 job_id =(84

select

85job_id

86from

87employees

88group

by89

job_id

90order

by91

**g(salary) desc

92 limit 1

93);

9495 #5

.查詢平均工資高於公司平均工資的部門有哪些?

96select

97**g

(salary),

98department_id

99from

100employees

101group

by102

department_id;

103104

105h**ing

106**g(salary) >

(107

select

108**g

(salary)

109from

110employees

111);

112113 #6

.查詢出公司中所有 manager的詳細資訊

114select

115*

116from

117employees

118where

119 employee_id in

(120

select

distinct

121manager_id

122from

123employees

124);

125126 #7

.各個部門中最高工資中最低的那個部門的最低工資是多少

127select

128min

(salary),

129department_id

130from

131employees

132where

133 department_id =

(134

select

135department_id

136from

137employees

138group

by139

department_id

140order

by141

max(salary)

142 limit 1

143);

144145 #8

.查詢平均工資最高的部門的 manager的詳細資訊:last_name, department id, email

146select

147last_name,

148d.department_id,

149email,

150salary

151from

152employees e

153join departments d on d.manager_id =

e.manager_id

154where

155 d.department_id =

(156

select

157department_id

158from

159employees

160group

by161

department_id

162order

by163

**g(salary) desc

164 limit 1

165 );

MySQL 子查詢 練習題

測試資料表 suppliers 表 s id s name s city s zip s call 101 fastfruit inc.tianjin 300000 48075 102lt supplies chongqing 400000 44333 103acme shanghai 200000...

mysql求和 子查詢 MySQL子查詢

到現在為止,我們已經表明,以select宣告是乙個簡單的查詢。該單個語句從單個資料庫表中檢索資料。sql還同意建立乙個子查詢。即巢狀在其他查詢的查詢。下列實施例給出巢狀查詢。一種表示訂單資訊儲存,包含訂單號,客戶id。訂購日期。例如以下所看到的 一張表示儲存訂單物品資訊,例如以下 另一張表儲存的是客...

習題11 6 查詢子串

習題11 6 查詢子串 20分 本題要求實現乙個字串查詢的簡單函式。char search char s,char t 函式search在字串s中查詢子串t,返回子串t在s中的首位址。若未找到,則返回null。include define maxs 30 char search char s,cha...