Forum Discussion
Hari117
Feb 20, 2023Copper Contributor
How to join three select sql statements
Hi, i have three select sql statements now i want to join those three statements into one table. for Example SELECT ID, COUNT(DISTINCT ORDER_ID) AS NUM_ACCT FROM SALES_TABLE GROUP BY ID -...
olafhelper
Feb 20, 2023Bronze Contributor
Hari117 , your base queries are always the same, so simply use all aggregations within one query
SELECT ID,
COUNT(DISTINCT ORDER_ID) AS NUM_ACCT,
COUNT(DISTINCT PARCEL_C1) AS NUM_ACCT,
COUNT(DISTINCT PARCEL_C1) AS NUM_ACCT2,
SUM(SALES_S) AS NUM_ACCT
FROM SALES_TABLE
GROUP BY ID