2013-11-04 84 views
0

現有的查詢:的Oracle SQL SELECT查詢

查詢-1:

select count(unique clientMacAddress) uniqueClients 
from ClientSessionInfo ClientSessionInfo 
where ClientSessionInfo.sessionStartTime >= 1383206920000 and ClientSessionInfo.sessionStartTime <=520000 

表中的列:

a. SessionStartTime 

b. clientMacAddress 

c. ConnectionType 

要求:

顯示總節數唯一有線客戶端和獨特的無線客戶端總數以及總數量。獨特的客戶端

如果connectionType = 0,則它被connectionType是 '無線' 如果connectionType = 1,則它被connectionType是 '有線'

解決方案: 查詢-1將返回總沒有唯一的客戶端。

再寫一個查詢(Query-2)來檢索無線客戶端。 查詢-2:

select count(unique clientMacAddress) uniqueClients 
from ClientSessionInfo ClientSessionInfo 
where ClientSessionInfo.sessionStartTime >= 1383206920000 and ClientSessionInfo.sessionStartTime <=520000 and connectionType = 0 

基於查詢-1和查詢的輸出-2,有線客戶端可以被驅動。

而不是編寫查詢-2,有沒有辦法修改查詢-1來檢索所需的結果。

回答

0

由子句使用group by子句來區分組

select connectionType, count(distinct clientMacAddress) 
from ClientSessionInfo csi 
where csi.sessionStartTime >= 1383206920000 and csi.sessionStartTime <=520000 
group by connectionType