0

I have tables called PATIENTINFO and MEDICATIONINFO with columns as mentioned below

PATIENTINFO

PatiendId      Disease
------------------------
1000            Fever
1001            Cold


MEDICATIONINFO

MedId     PatiendId    Medicine     Value    Reaction
------------------------------------------------------
100         1000         Med1        100       R
101         1000         Med2        200       L
102         1000         Med3        150       H
103         1001         Med1        120       L
104         1001         Med2        150       R
105         1001         Med3        300       H

I want result to be in the below format (Hibernate query)

Medicine    Value1     Reaction1     Value2     Reaction2 .......(Value n ...Reaction n)  
----------------------------------------------------------------
Med1            100           R       120          L
Med2            200           L       150          R
Med3            150           H       300          H

Can anyone help me out in this??

4

1 に答える 1

0
    SELECT
    MINFO.Medicine,
    MINFO.Reaction1,
    SUM(CASE WHEN MINFO.Reaction = 'R' THEN Value ELSE 0 END) Value1,
    SUM(CASE WHEN MINFO.Reaction = 'L' THEN Value ELSE 0 END) Value2,
    SUM(CASE WHEN MINFO.Reaction = 'H' THEN Value ELSE 0 END) Value3,
FROM PATIENTINFO PINFO
    LEFT JOIN MEDICATIONINFO MINFO
        ON PINFO.PatiendId  = MINFO.PatiendId
GROUP BY MINFO.Reaction
于 2013-03-26T12:58:28.773 に答える