0
Hello! I’m trying to return the names of people and the amount of cars each has according to the 2 tables below, but accuses the following error:
ORA-00979: not a GROUP BY Expression 00979. 00000 - "not a GROUP BY Expression"
Here are my 2 tables:
create table pessoa(
idpessoa number not null,
nome varchar2(40) not null,
constraint pk_idpessoa primary key(idpessoa)
);
create table carro(
idcarro number not null,
nome_carro varchar2(40) not null,
idpessoa number not null,
constraint fk_idcarro foreign key(idpessoa) references pessoaA(idpessoa)
);
/*INSERT'S CASO VOCÊ QUEIRA TESTAR*/
insert into pessoa values(1, 'Maria');
insert into pessoa values(2, 'Joao');
insert into carro values(1, 'Fusca', 1);
insert into carro values(2, 'Kombi', 1);
insert into carro values(3, 'Opala', 2);
Return only quantity works...
select count(carro.idcarro) from carro group by carro.idpessoa;
However, when I put to return also the person’s name results in error
select pessoa.nome, count(carro.idcarro) from pessoa, carro group by carro.idpessoa;
I tested this last line this way because in Mysql it works, already in Oracle no :/ . Can someone help me?
select person.name, Count(car.idcar) from person, car group by person.name; .... in Oracle the select fields must be in "group by"
– Motta
Thank you very much! I didn’t know it! Although the code is still not generating what I expect (it doesn’t show each person but the total), it helped me a lot!
– Rogério