简体   繁体   中英

How to select count of two distinct columns?

我想计算从这个SQL返回的不同COMPONENT_ID和PACKAGE_ID的总数。

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
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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