只有在09个月出生时才能获得客户

时间:2016-03-10 11:27:00

标签: sql oracle date

我遇到“无效关系运营商”消息的问题

select distinct ig.describe from info_groupe ig 
inner join client_info ki on (ig.id=ki.id_info_group) 
where exists (select * from client k inner join client_contact kk
on (k.id=kk.id_client)  where kk.location='B'
 and kk.type_contact= 'EMAIL'
 AND substr(date, 4, 2),
 'dd.mm.yyyy'), 'MM' ='09' 
 order by describe desc; 

除了月份,我必须满足location ="B"type_contact = "EMAIL"的条件。 我想要的是显示“describe”,条件位置为B,并键入contact = Email给所有有日期的客户(例如01.09.88)09月

2 个答案:

答案 0 :(得分:3)

您可以使用EXTRACT( MONTH FROM <date column> )

select distinct ig.describe
from   info_groupe ig 
       inner join client_info ki
       on (ig.id=ki.id_info_group) 
where exists ( select *
               from   client k
                      inner join client_contact kk
                      on (k.id=kk.id_client)
               where  kk.location='B'
               and    kk.type_contact= 'EMAIL'
               AND    EXTRACT( MONTH FROM date ) = 9
             ) 
order by describe desc; 

答案 1 :(得分:1)

试试这个:

select distinct ig.describe from info_groupe ig 
inner join client_info ki on (ig.id=ki.id_info_group) 
where exists (select * from client k inner join client_contact kk
               on (k.id=kk.id_client)  where kk.location='B'
                 and kk.type_contact= 'EMAIL'
                 AND to_char(date,'MM') ='09' 
                 AND ki.id = kk.id_client)
order by describe desc

我假设你在client_info中有客户端id的列,我称之为id_client,如果它不同则更改它。

我用to_char(日期,&#39; MM&#39;)来获得月份。