查询年龄

query on years old

我会解决这个问题

Display id, dates and time of all "LASER" interventions involving only doctors Having less than 30 years.

但我有一个错误:

select i.id, i.data_e_ora

from persona p join medico m

on p.cf=m.cf

join effettua e

on m.cf=e.cf_med

join intervento i

on e.id_int=i.id

where i.tipo='LASER' and p.data_nascita=((sysdate-p.data_nascita)/365)<30

ERROR at line 9:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER

table:

 CF                                        NOT NULL CHAR(16)
 NOME                                               VARCHAR2(30)
 COGNOME                                            VARCHAR2(30)
 DATA_NASCITA                                       DATE
 SESSO                                              CHAR(1)

您只需修复 where 子句。野心太大了:

select i.id, i.data_e_ora
from persona p join
     medico m
     on p.cf = m.cf join
     effettua e
     on m.cf = e.cf_med join
     intervento i
     on e.id_int = i.id
where i.tipo = 'LASER' and
      p.data_nascita > (sysdate - 365.25 * 30);

注意:减去年数的更好方法是实际减去年数:

where p.data_nascita > sysdate - interval '30' year