SQL - doubt in query

Asked

Viewed 36 times

0

I have the following appointment to do, I was able to think of them separately. I’m starting to study databases and I don’t know how to relate the two.

Table Occurrence number, date, description, cpfprofissionalseg

Table Occurrenceperson {cpfpessoa, numero ocorrencia}

Table Spectator {cpfpessoa, code}

Table Person {Cpf, date of birth, name, type }

"For each spectator, select CPF, name, code and, if involved in any occurrence, include date (no time) and occurrence description."

SELECT p.cpf, p.nome, e.codigo 
FROM pessoa p, espectador e 
INNER JOIN p ON e.cpfpessoa = p.cpf

SELECT o.data, o.descricao 
FROM ocorrencia o, ocorrenciapessoa op

1 answer

0

Your join syntax is wrong.
Try:

SELECT p.cpf, p.nome, e.codigo, o.data, o.descricao 
FROM pessoa p 
INNER JOIN espectador e ON e.cpfpessoa = p.cpf
INNER JOIN Ocorrenciapessoa op ON e.cpfpessoa = e.cpfpessoa
INNER JOIN ocorrencia o ON o.numero = op.numeroocorrencia

You did not enter the format of the date field to specify it "no time".

  • TO_DATE('1987/01/12 00:00:00', 'yyyy/mm/dd hh24:mi:ss') This is the format

  • So don’t specify time, minute and second.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.