mysql - selecting multiple rows in one table with different fields -
i have following queries:
select count(id) table_1 field_1 = 1
select count(id) table_1 field_2 = 1
select count(id) table_1 field_2 = 1
can done in single query.. 1 table use 3 outputs like:
count(id) | count(id) | count(id)<br> 12 | 44 | 55
yes can use result using aggregate function case expression similar following:
select sum(case when field_1 = 1 1 else 0 end) field1total, sum(case when field_2 = 1 1 else 0 end) field2total table_1
you add more sum(case...)
expression remaining items want total.
Comments
Post a Comment