티스토리 뷰

공부

[SQL] count distinct with conditions

승가비 2020. 7. 24. 19:48
728x90
select
  count(distinct tag) as tag_count,
  count(distinct (case when entryId > 0 then tag end)) as positive_tag_count
from
  your_table_name;

https://stackoverflow.com/questions/14048098/count-distinct-with-conditions

 

COUNT DISTINCT with CONDITIONS

I want to count the number of distinct items in a column subject to a certain condition, for example if the table is like this: tag | entryID ----+--------- foo | 0 foo | 0 bar | 3 If I want to c...

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

FQDN(Fully Qualified Domain Name)  (0) 2020.07.24
[Hive] parse JSON  (0) 2020.07.24
[Maven] build project without version  (0) 2020.07.24
[Hive] get json keys  (0) 2020.07.24
[Spark] from_unixtime & to_timestamp  (0) 2020.07.24
댓글