在SQL中执行多列的COUNTS DISTINCT的SUM

时间:2015-01-07 16:23:30

标签: mysql count distinct

COUNT(DISTINCT invoiceType1)` AS `#invoices2`, 
COUNT(DISTINCT invoiceType2)` AS `#invoices2`, 

有没有办法将这两个计数加在一起?虽然它们都是DISTINCT但我不确定它是否会表现正常。

谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个,只需使用'+'运算符

添加这两个计数
SELECT
COUNT(DISTINCT invoiceType1) AS #invoices1, 
COUNT(DISTINCT invoiceType2) AS #invoices2, 
COUNT(DISTINCT invoiceType1) + COUNT(DISTINCT invoiceType2) AS #totalinvoicescount
FROM tablename