Home > Software design >  How to extend the result of the query into separate column in SQL?
How to extend the result of the query into separate column in SQL?

Time:09-28

SELECT 
  COUNT (*)
  FROM table
  WHERE coloumn2 > 10
UNION 
SELECT 
  COUNT (*)
  FROM table
  WHERE coloumn3 > 10
UNION 
SELECT 
  COUNT (*)
  FROM table
  WHERE coloumn3 > 10
UNION 

Results:

(No column name)
155
433
931

How to put the results into a new column?

Coloumn1    Coloumn2    Coloumn2
155         433          931

CodePudding user response:

SELECT
(
  SELECT 
    COUNT (*)
    FROM table
    WHERE coloumn2 > 10
) AS [col1],
(
  SELECT 
    COUNT (*)
    FROM table
  WHERE coloumn3 > 10
) AS [col2],
(
  SELECT 
    COUNT (*)
    FROM table
  WHERE coloumn3 > 10
) AS [col3]

should do the trick

  •  Tags:  
  • sql
  • Related