i have a table 'operation_record' like this:
date operation
1-1 a
1-1 b
1-1 b
1-1 a
1-1 a
1-1 c
1-1 a
1-2 c
1-2 b
1-2 c
1-2 a
1-2 a
1-2 b
1-2 c
and what I want is like this:
data operation_a operation_b operation_c
1-1 4 2 1
1-2 2 2 3
if the operations is fixed, i can use things like this:
select o.uc, ,a.rc operaiton_a, b.rc operaiton_b, c.rc operaiton_c from
(select date uc,count(1) rc from operaion_record group by date) o
left join
(select date uc,count(1) rc from operaion_record where operation='a' group by date)a on o.uc=a.uc
left join
(select date uc,count(1) rc from operaion_record where operation='b' group by date)b on o.uc=b.uc
left join
(select date uc,count(1) rc from operaion_record where operation='c' group by date)b on o.uc=c.uc
but the problem is, the operation maybe varied.
though ,i can get these operations by
select distinct(operation) from operation_record
then, how can I make this values as new columns and got those counts?