IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New One solution
(SELECT distinct O.orderdate, O.ordernum, 'x' as OpenEscalations
from tbl_order O
INNER JOIN tbl_escalation E on O.ordernum = E.ordernum
where E.escalation = 'open')
UNION ALL
(SELECT distinct O.orderdate, O.ordernum, ' '
from tbl_order O
LEFT JOIN tbl_escalation E on O.ordernum = E.ordernum and E.escalation = 'open'
where E.escalation IS NULL)
order by OpenEscalations desc, ordernum

Not the neatest solution, but as long as the data you are looking at is not huge it should be fast.

Jay
New FWIW this was the best I saw for our needs
The union did in fact get the exact right results. And was the clearest in what it was doing. Then someone observed that the main table was already an aggregate of results from several other tables, built just for running this one report. There are no other joins against it. The right way for us to do this is check and update (if necessary) the value of a flag in the main table every time we update an escalation.

All the other solutions suffer from the same problem. In order to get the correct data we'd have to order a specific way before grouping. But if that isn't the way we want the output ordered, we end up re-sorting in code anyway.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
     How to do without subqueries - (drewk) - (18)
         SELECT DISTINCT t1.* FROM t1, t2 ...? - (FuManChu)
         I don't understand your description - (ben_tilly) - (16)
             Reply from Drew - (Meerkat) - (15)
                 Re: Reply from Drew - (SpiceWare) - (6)
                     DECODE is Oracle-specific. -NT - (ben_tilly) - (5)
                         It is, but it is easy to clone - (tuberculosis)
                         Are you sure? I checked MySQL before posting - (SpiceWare) - (3)
                             They may have added it but it is not standard - (ben_tilly)
                             Seems to be specific to MaxDB - (JayMehaffey) - (1)
                                 That's rather confusing - (SpiceWare)
                 One solution - (JayMehaffey) - (1)
                     FWIW this was the best I saw for our needs - (drewk)
                 Untested, googling for supported syntax - (ben_tilly)
                 Re: Reply from Drew - (dws) - (4)
                     You're ordering by the wrong thing - (ben_tilly) - (3)
                         Where do you see me ordering by count(*) ? -NT - (dws) - (2)
                             You weren't, clarification - (ben_tilly) - (1)
                                 Re: You weren't, clarification - (dws)

Gloat.
77 ms