| | 29 | |
| | 30 | OK onto the fun stuff, pivot tables. The most evil nasty piece of poo you can think to do with databases. |
| | 31 | {{{ |
| | 32 | #!html |
| | 33 | <pre> |
| | 34 | CREATE OR REPLACE VIEW not_started_sensors_pivot AS |
| | 35 | SELECT * |
| | 36 | FROM crosstab('SELECT fs.flight_id, fs.priority, fs.sensor_name || ''|'' || ss.progress || ''|'' || ss.username |
| | 37 | FROM flight_sensors fs |
| | 38 | JOIN not_finished_sensors ss |
| | 39 | ON (fs.id = ss.flight_sensor_id) |
| | 40 | JOIN priorities p |
| | 41 | ON (fs.priority = p.priority_name) |
| | 42 | WHERE ss.progress IN (''not_started'', ''blocked'') |
| | 43 | AND fs.priority NOT IN (''not_required'', ''unfunded'') |
| | 44 | ORDER BY p.value DESC, ss.submit_time, fs.sensor_name ASC') |
| | 45 | AS ct(id int, c1 text, c2 text, c3 text, c4 text, c5 text, c6 text, c7 text, c8 text, c9 text); |
| | 46 | </pre> |
| | 47 | }}} |