[RndTbl] SQL problem

John Lange john at johnlange.ca
Thu Mar 24 11:50:20 CDT 2016


What Adam said; something like:

SELECT custid, (select count(*) FROM ordertable where TTL=X), (select
count(*) FROM ordertable where TTL=Y)
FROM ordertable
order by custid;


On Thu, Mar 24, 2016 at 9:21 AM, Adam Thompson <athompso at athompso.net>
wrote:

> Subqueries:
> SELECT (SELECT ...), (SELECT ...) FROM ...
>
> If they don't work, upgrade to a newer version of MariaDB. (If this is the
> customer I assume it is, use RackSpace's IUS repo to upgrade).
>
> Alternately, create two VIEWs, one for each aggregate count, and OUTER
> JOIN them.
> -Adam
>
>
> On March 24, 2016 9:16:31 AM CDT, Trevor Cordes <trevor at tecnopolis.ca>
> wrote:
>>
>> Can anyone help me figure out how to do this in SQL (MySQL)?
>>
>> (pseudo-code giving you the gist):
>>
>> SELECT custid, (count orders where ttl=X), (count orders where ttl=Y)
>> FROM ordertable
>> GROUP BY custid;
>>
>>
>> I basically want to count two different things based on two different
>> wheres.  If I put in a where clause then I select either the X or the Y
>> but I can't seem to get both in such a way I can count the X's and Y's.  I
>> tried thinking about unions but couldn't make it work.  I want to do this
>> all in 1 query as I want the sorted union of all custid's (X and Y).
>>
>> P.S. ordertable has/can have multiple entries for each custid.
>>
>> Ideas are appreciated!
>> ------------------------------
>>
>> Roundtable mailing list
>> Roundtable at muug.mb.ca
>> http://www.muug.mb.ca/mailman/listinfo/roundtable
>>
>>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>
> _______________________________________________
> Roundtable mailing list
> Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable
>
>


-- 
John Lange
www.johnlange.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.muug.mb.ca/pipermail/roundtable/attachments/20160324/1e6b6fb6/attachment.html>


More information about the Roundtable mailing list