mardi 27 octobre 2015

How to show x,y,count(*) in 2-D by one SQL?

For example data in csv is

#row, col, number
y1,x1,1
y2,x2,1
y2,x2,1
y2,x3,1

If I use simple group SQL, it can displayed as one dimension

select y1,x1,count(*) from data group by 1,2 order by 1,2

The 1-D result is

row col count(*)
y1  x1  1
y2  x2  2
y2  x3  3

I want to show like

row x1 x2 x3
y1   1  0 0
y2   0  2 1

If the col is limited in only 'x1','x2','x3', is it possible to use one SQL to display as 2-D?

Aucun commentaire:

Enregistrer un commentaire