0

I have two tables similar to these (t_stamp would normally be a DATETIME, abbreviated here for clarity):

datapoints    
+------+---------+----+---------+
| ndx  |  value  | ID | t_stamp |
+------+---------+----+---------+
|  1   | 503.42  |  1 | 3/1/15  |
|  2   | 17.81   |  2 | 3/1/15  |
|  4   | 498.21  |  1 | 3/2/15  |
|  4   | 19.51   |  2 | 3/2/15  |
+------+---------+----+---------+

parameters    
+------+----+---------------+-------+
| ndx  | ID | description   | unit  |
+------+----+---------------+-------+
|  1   |  1 | wetwell level |  ft   |
|  2   |  2 | effluent flow |  MGD  |
+------+----+---------------+-------+

I'm looking to combine them so that the descriptions become column headers and list the values in order of time stamp, end result looking something like this:

new table    
+---------+---------------+---------------+
| t_stamp | wetwell level | effluent flow |
+---------+---------------+---------------+
| 3/1/15  |    503.42     |    17.81      |
| 3/2/15  |    498.21     |    19.51      |
+---------+---------------+---------------+

Bearing in mind, I have considerably more rows in each table so I'm looking for something dynamic. It could be query or stored procedure based. Thank you for any help!

jason
  • 1
  • 2
  • Try here: http://stackoverflow.com/questions/1241178/mysql-rows-to-columns – bdn02 Mar 03 '15 at 19:30
  • Thank you! That got me half way there, still struggling with the pivot ordering by t_stamp... but I'll keep at it. – jason Mar 05 '15 at 01:00

0 Answers0