sql query to count two type in single cloumn -


buses ---------------- |bus_no     |bus_name |type |avail_seat 

i have calculate how many ac , non ac buses there?

my query count is:

count(*)bus_count sum(case when type='ac' 1 else 0) sum (case when type="non ac" 1 else 0) buses group bus_number; 

assuming there 2 values in 'type' column, following query work:

select type,  count (*) bus_count bus group 1;  


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -