Code:
SELECT
DISTINCT u.email,
su.metaInfo,
(SELECT count(*) as viewCount
FROM StatisticEvent se, Subscription s
WHERE se.eventType = 'display' and
se.subscription.id = s.id and
s.campaign.id = 1 and
s.user.id=u.id) ,
(SELECT count(*) as clickCount
FROM StatisticEvent se, Subscription s
WHERE se.eventType = 'click' and
se.subscription.id = s.id and
s.campaign.id = 1 and
s.user.id=u.id) as clicks
FROM User u, Subscription su
WHERE u.id = su.user.id AND su.campaign.id = 1
ORDER BY u.email
I can easily order by the email field, but how do I order by one of the anonymous nested queries? As you can see I have tried some aliasing but never had any success.