需要查询以显示同时拥有男性和女性员工的部门
CREATE TABLE departments(deptname VARCHAr2(20),sex VARCHAR2(2));
INSERT INTO departments VALUES('SALES','M');
INSERT INTO departments VALUES('SALES','F');
INSERT INTO departments VALUES('SALES','M');
INSERT INTO departments VALUES('SALES','F');
INSERT INTO departments VALUES('ENG','M');
INSERT INTO departments VALUES('ENG','F');
INSERT INTO departments VALUES('MKT','M');
INSERT INTO departments VALUES('CLE','F');
INSERT INTO departments VALUES('AUTO','M');
INSERT INTO departments VALUES('AUTO','M');
INSERT INTO departments VALUES('ENV','F');
INSERT INTO departments VALUES('ENV','F');
Expected Output
Deptname Sex
SALES M
SALES F
SALES M
SALES F
ENG M
ENG F
请帮帮我。
先谢了。
3条答案
按热度按时间jutyujz01#
或者使用窗口函数来避免两次击中table:
zbwhf8kr2#
您可以:
wdebmtf23#
在Oracle 12中,您可以用途:
其输出:
| DEPTNAME|性|
| - ------|- ------|
| 英语|F级|
| 英语|男|
| 销售|F级|
| 销售|F级|
| 销售|男|
| 销售|男|
fiddle