[英]Oracle SQL Select Query
现有查询:
查询-1:
select count(unique clientMacAddress) uniqueClients
from ClientSessionInfo ClientSessionInfo
where ClientSessionInfo.sessionStartTime >= 1383206920000 and ClientSessionInfo.sessionStartTime <= 1383210520000
表格中的栏:
a. SessionStartTime
b. clientMacAddress
c. ConnectionType
要求:
显示唯一有线客户端的总数,唯一无线客户端的总数以及唯一客户端的总数
如果connectionType = 0,则连接类型为“无线”;如果connectionType = 1,则连接类型为“有线”
解决方案:查询-1将返回唯一客户端总数。
再编写一个查询(Query-2)以检索无线客户端。 查询-2:
select count(unique clientMacAddress) uniqueClients
from ClientSessionInfo ClientSessionInfo
where ClientSessionInfo.sessionStartTime >= 1383206920000 and ClientSessionInfo.sessionStartTime <= 1383210520000 and connectionType = 0
基于查询-1和查询-2的输出,可以驱动有线客户端。
除了编写查询-2之外,没有任何方法可以修改查询-1以检索所需的结果。
使用group by子句区分group by子句
select connectionType, count(distinct clientMacAddress)
from ClientSessionInfo csi
where csi.sessionStartTime >= 1383206920000 and csi.sessionStartTime <=1383210520000
group by connectionType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.