查詢

2017-07-15 54 views
-1

,我會解決這個查詢查詢

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 

表:

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

你讀過的錯誤消息?因爲它確切地告訴你你想知道什麼。日期列(p.data_nascita)存儲爲數字(可能是UNIX時間戳)而不是日期 – Daniel

+0

您應該真正編輯您的問題以顯示錶格模式。 –

回答

0

你只需要修復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 
+0

爲什麼使用:(sysdate - 365.25 * 30); ??? – Rock

+0

@Rock因爲這個表達式總是會在30年前評估到第二個,這是OP要求的。 *這就是爲什麼戈登認爲它過於雄心勃勃。當然,如果有成千上萬的醫生和大多數醫生每年執行數百次激光干預(黃斑變性治療?),並且數據庫服務器上的數據沒有OLAP,那麼是的,這是過於雄心勃勃的。 – jeff6times7

+0

簡單的syntacx存在嗎? – Rock