mysql - Conditional SQL report -


suppose have table contains:

serial#  colorcount   bwcount ============================== 12345            23        56 80023             0       459 22903             1       999 

and want generate report looks like:

sn     description    value ============================== 12345  "bwcount"      56 12345  "colourcount"  23 80023  "bwcount"      459 22903  "bwcount"      999 22903  "colourcount"  1 

so that...

  1. the bwcount , colourcount values output different rows, and
  2. if colourcount value device (sn) 0 not output

is possible raw sql? , if yes, please show me how or point me in right direction. i've done work mysql simple queries. have never seen done before.

you union 2 queries return data need, example:

select serial, 'bwcount' description, bwcount value serial  union select serial, 'colourcount' description, colourcount value serial  colourcount > 0 

demo: http://sqlfiddle.com/#!9/f97b6/3


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

python - No response in ssh.exec_command in paramiko -