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
----------------------------------------
SELECT ID,
COUNT(DISTINCT PARCEL_C1) AS NUM_ACCT,
COUNT(DISTINCTPARCEL_C1) AS NUM_ACCT2,
FROM SALES_TABLE
GROUP BY ID
---------------------------------------
SELECT ID,
SUM(SALES_S) AS NUM_ACCT,
FROM SALES_TABLE
GROUP BY ID
i am running separately Now I want to join the above 3 select queries in to one table
1 Reply
- olafhelperBronze 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