简体   繁体   中英

How to get combined output from two or more than two queries?

I have one table ABC . I am using queries

select count(*) from ABC where COLA=123; //output is 3

select count(*) from ABC WHERE COLA=321; //output is 6

I want both output combined like

| someColumnName |
|    3           |
|    6           |

Is there any way to frame query so that I can achieve this?

Use UNION between your two queries:

select count(*) as someColumnName  from ABC where COLA=123
union
select count(*) from ABC WHERE COLA=321;

use a group by and where clause.

SELECT count(*) as SomeColumnName
FROM ABC 
WHERE COLA in (123,321)
GROUP BY ColA

Just another option:

SELECT count(*) as SomeColumnName
FROM ABC 
WHERE COLA = 123 
   OR COLA = 321
GROUP BY COlA;

:)

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