mercredi 20 mai 2015

What SELECT statement will get the non-zero values from table rows?

If I have multiple rows in a table of 27 columns which are all integers like this

id_1    id_2    id_3    id_4    id_5    id_6    id_7    id_8    id_9    id_10   id_11   id_12   id_13   id_14   id_15   id_16   id_17   id_18   id_19   id_20   id_21   id_22   id_23   id_24   id_25   id_26   id_27
0       2       0       4       5       0       0       8       0       10      0       0       0       14      0       0       17      0       0       0       21      0       0       0       0       0       0

and I wanted to run a SELECT statement to get a maximum of 8 columns which are > zero (there will never be more than 8) what would be the best, or at least functional, way of doing it? In the event of there not being 8 values > 0 then NULLS are allowed. So the resulting table from the above would be.

col1 col2 col3 col4 col5 col6 col7 col8
2    4    5    8    10   14   17   21

Aucun commentaire:

Enregistrer un commentaire