Query join

  • Now working, thank you.

    SELECT Coalesce( sGIG, 'Tot' ) as sGIG, Sum(Number) as Num

    FROM (

    SELECT LEFT (idDGIG, 2) AS sGIG, COUNT(idDGIG) AS NUMBER

    FROM TABLE_LONG

    WHERE

    LEFT (idDGIG, 2) IN ('QM', 'QI', 'QO', 'QS')

    AND DATE_START = DATE_ADD(CURDATE(), INTERVAL - 1 DAY)

    GROUP BY sGIG

    UNION ALL

    SELECT LEFT (idDGIG, 2) AS sGIG, COUNT(idDGIG) AS NUMBER

    FROM TABLE_SHORT

    WHERE

    LEFT (idDGIG, 2) IN ('QM', 'QI', 'QO', 'QS')

    AND DATE_START = DATE_ADD(CURDATE(), INTERVAL - 1 DAY)

    GROUP BY sGIG

    ) AS sums

    Group by sGIG WITH ROLLUP;

    +--------+--------+

    | sGIG | NUMBER |

    +--------+--------+

    | QI | 11 |

    | QM | 4 |

    | QO | 22 |

    | QS | 11 |

    | Tot | 48 |

    +--------+--------+

  • Great to hear you got it working. But please remember next time around you ask a question to please provide us with enough info to actually help you. So please read through Jeff's first link in his signature. We can't see what you see on your side, and without that info we're just taking a guess, probably wasting your time and ours as well. Anyhow, welcome to SSC!

    --------------------------------------------------------------------------
    A little knowledge is a dangerous thing (Alexander Pope)
    In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)[/url]

  • Jan Van der Eecken (3/31/2013)


    Great to hear you got it working. But please remember next time around you ask a question to please provide us with enough info to actually help you. So please read through Jeff's first link in his signature. We can't see what you see on your side, and without that info we're just taking a guess, probably wasting your time and ours as well. Anyhow, welcome to SSC!

    Of course !

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply