对mysql值进行排序并选择最大值

时间:2014-04-29 18:14:54

标签: php mysql

我有一个名为mydatabase.db的数据库和一个名为mytable的表。 在我的桌子里面有这样的行:

Name    A       B      C       D      E      F     G      H
Andy    1       2      3       4      5      6     7      7

我只想选择大于5的值。在这种情况下,表示F,G,H。 知道怎么样?

1 个答案:

答案 0 :(得分:0)

试试这个

 select 
 name ,
 max(case when A > 5 then A else 'null' end )as 'A',
 max(case when B > 5 then B else 'null' end )as 'B',
 max(case when C > 5 then C else 'null' end )as 'C',
 max(case when D > 5 then D else 'null' end )as 'D',
 max(case when E > 5 then E else 'null' end )as 'E',
 max(case when F > 5 then F else 'null' end )as 'F',
 max(case when G > 5 then G else 'null' end )as 'G',
 max(case when H > 5 then H else 'null' end )as 'H'

 FROM table1

DEMO HERE

并且你可以在php中创建条件,如果某些列=' null'然后不要显示它。