Note that there are some explanatory texts on larger screens.

plurals
  1. POTranspose rows in mysql with three columns
    primarykey
    data
    text
    <p>I have this table in mysql:</p> <pre><code>id | orden | pacient | per| exam | value | condition | date ---+---------------+----------+----+-------+-------+------------+-------------------- 1 | 201208082001 | 20652598 | 0 | 1017 | 9.00 | 0 | 2012-08-08 09:28:21 2 | 201208082001 | 20652598 | 0 | 1018 | 4.80 | 0 | 2012-08-08 09:28:21 3 | 201208082001 | 20652598 | 0 | 4104 | 213.00| 0 | 2012-08-08 09:28:21 4 | 201208082002 | 2799592 | 0 | 1017 | 7.70 | 0 | 2012-08-08 09:29:21 5 | 201208082002 | 2799592 | 0 | 1018 | 2.40 | 0 | 2012-08-08 09:29:21 6 | 201208082002 | 2799592 | 0 | 4104 | 43.00 | 0 | 2012-08-08 09:29:21 7 | 201208082003 | 6058327 | 0 | 1017 | 9.10 | 0 | 2012-08-08 09:30:02 8 | 201208082003 | 6058327 | 0 | 1018 | 4.00 | 0 | 2012-08-08 09:30:02 9 | 201208082003 | 6058327 | 0 | 4104 | 840.00| 0 | 2012-08-08 09:30:02 </code></pre> <p>What I need is this: each <em>set</em> of three rows has the same <code>orden</code> the same <code>pacient</code> and different <code>exams</code> and <code>values</code>. There is always a <code>CA</code> value, a <code>P</code> value and a <code>PTH</code> value. I need to check wherever a <code>pacient</code> have a <code>CA &gt; 5.5</code> and a <code>P &gt; 11</code> (and other bunch of things) in the original form of the table is very hard to get this quick and easy.</p> <pre><code>id | orden | pacient | per| CA | P | PTH | condition | date ---+---------------+----------+----+-------+------+------- +-----------+-------------------- 1 | 201208082001 | 20652598 | 0 | 9.00 | 4.80 | 213.00 | 0 | 2012-08-08 09:28:21 2 | 201208082002 | 2799592 | 0 | 7.70 | 2.40 | 43.00 | 0 | 2012-08-08 09:28:21 3 | 201208082003 | 6058327 | 0 | 9.10 | 4.00 | 840.00 | 0 | 2012-08-08 09:28:21 </code></pre> <p>This transposed table will be in a view, I have tried with sub-queries but is extremely slow, so. I hope you could help me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload