简体   繁体   English

选择计数不同的查询

[英]Select count distinct query

Writing a query that will give me the total count of an event rather than counting the event every time it happens编写一个查询,它会给我一个事件的总数,而不是每次发生时都计算事件

Ok so I'm trying to write a query that will count the number of session IDs for that each distinct account id, program id and device id has.So for example.好的,所以我正在尝试编写一个查询,该查询将为每个不同的帐户 ID、程序 ID 和设备 ID 计算会话 ID 的数量。例如。 acct id 1 has 3 devices watching the same program with 3 different session IDs. acct id 1 有 3 个设备使用 3 个不同的会话 ID 观看同一节目。 I want my query to give me Acct id 1 has 3 sessions.我希望我的查询给我 Acct id 1 有 3 个会话。 The current query i have is just listing the number of sessions like this我当前的查询只是列出这样的会话数

Acct ID 01 Session 1, Acct ID 01 Session 1


SELECT count( DISTINCT source_session_id), acct_id, device_id, program_id,  event_date
FROM TABLE 
WHERE condition 
group by source_session_id, acct_id, device_id, program_id, event_date;

I would like the end result of my query to be Acct ID 01 # of Sessions 2我希望我的查询的最终结果是 Acct ID 01 # of Sessions 2

Try removing source_session_id from the Group By clause or you will get a row for each different source_session_id.尝试从 Group By 子句中删除 source_session_id,否则每个不同的 source_session_id 都会得到一行。

SELECT count( DISTINCT source_session_id), acct_id, device_id, program_id,  event_date
FROM TABLE 
WHERE condition 
group by acct_id, device_id, program_id, event_date;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM