0

Estou com dificuldades para fazer um SELECT. Preciso listar todas as informações(dcodigo, dnome) dos departamento(DEPT) que possuem um gerente(cargo). Meu código está assim:

create database bd_emp;
use bd_emp;

create table DEPT(
dcodigo int unsigned primary key not null
        auto_increment,
dnome varchar(36) not null
);

create table EMPR(
matr int unsigned key not null 
        auto_increment,
nome varchar(12) not null,
sobrenome varchar(15) not null,
dept int unsigned,
fone varchar(14),
dinadim date,
cargo varchar(10),
niveled decimal,
sexo char(1),
datanas date,
salario decimal(9.2),
bonus decimal(9.2),
comis decimal(9.2),
foreign key(dept) references DEPT(dcodigo)
);

create table PROJETOS(
pcodigo int unsigned not null primary key,
pnome varchar(24) not null,
dcodigo int unsigned not null,
resp int unsigned not null,
equipe int unsigned,
dataini date,
datafim date,
psuper varchar(6),
foreign key(dcodigo) references DEPT(dcodigo),
foreign key(resp) references EMPR(matr)
);

insert into DEPT values 
(null, 'informatica'),
(null, 'limpeza'),
(null, 'administracao'),
(null, 'alimentacao'),
(null, 'seguranca');

insert into EMPR values
(null, 'Rogério', 'Gás', 1, 995827541, '2017-02-14', 'técnico', 8, 'M', '1999-05-12', 32000, 2500, 500),
(null, 'Claudio', 'Roberto', 2, 994827541, '2018-05-11', 'faxineiro', 5, 'M', '1990-12-25', 14400, 200, 100),
(null, 'Rodrigo', 'Henrique', 3, 995827641, '2018-09-29', 'gerente', 12, 'M', '1999-12-04', 50000, 1000, 600),
(null, 'Maria', 'Fernanda', 4, 995487541, '2017-05-20', 'cozinheira', 6, 'F', '1989-12-06', 14400, 2500, 500),
(null, 'Cleiton', 'Xesque', 5, 995647541, '2019-07-12', 'guardinha', 7, 'M', '1986-12-09', 14400, 2500, 500);

No meu caso, somente o departamento administracao tem um gerente. Grato desde já

1

1 Resposta 1

1

Problema Resolvido.

select DEPT.dcodigo, DEPT.dnome from EMPR, DEPT 
where EMPR.dept=DEPT.dcodigo and EMPR.cargo='gerente';

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .