2016-12-09 65 views
1

我有一張表可以保存客戶輸入的url。當用戶登錄時,它會在審計表中保存URL'/ auth-engine/login'。 該表還包含時間戳以保存登錄日期。sql select沒有登錄的用戶

我想這並沒有time.Here的一個特定時期我試圖登錄的用戶的查詢:

select Distinct customer.customer_id ,concat(customer.first_name, ' ', customer.last_name) as name 
from customer 
Where customer.customer_id not in (
select Distinct customer.customer_id 
from customer 
inner join audit on customer.customer_id = audit.username 
where audit.url = '/auth-engine/login' And audit.server_response_code in ('200' , '201') 
And audit.ts_created Between '2016-01-01' And '2016-12-31') 

但是它沒有給我預期的結果。 我該怎麼做?

謝謝

+0

你肯定customer.customer_id = audit.username是正確的? –

+0

你正在使用哪些DBMS? –

回答

0

可以使用left joinwhere...is null

select * 
from customer 
left join audit 
    on customer.customer_id = audit.username 
    and audit.url = '/auth-engine/login' 
    And audit.server_response_code in ('200' , '201') 
    And audit.ts_created Between '2016-01-01' And '2016-12-31' 

where audit.username is null