开发者

How to select count of two distinct columns?

开发者 https://www.devze.com 2023-03-29 08:13 出处:网络
I would like to do a count of the total number of distinct COMPONENT_ID and PACKAGE_ID returned from this SQL.

I would like to do a count of the total number of distinct COMPONENT_ID and PACKAGE_ID returned from this SQL.

开发者_运维知识库
SELECT DISTINCT COMPONENT_ID, PACKAGE_ID FROM BILL;


You can use:

select count(distinct (COMPONENT_ID || PACKAGE_ID))
  from BILL;

Provided || is the string concatenation operator.


select count(*)
from
(
    select distinct component_id, package_id
    from yourtable
) as distinctquery


SELECT COUNT(*) FROM (
    SELECT DISTINCT component_id FROM bill
    UNION SELECT DISTINCT package_id FROM bill
)
0

精彩评论

暂无评论...
验证码 换一张
取 消