<div dir="ltr">Sorry, I see that was totally wrong... You&#39;d need something like below but I don&#39;t think this will work as-is...<div><br></div><div><div style="font-size:12.8px"><span style="font-size:12.8px">SELECT custid as cid, (select count(*) FROM ordertable where custid=cid and TTL=X), (select count(*) FROM ordertable where </span><span style="font-size:12.8px">custid=cid and</span><span style="font-size:12.8px"> </span><span style="font-size:12.8px">TTL=Y)</span></div><div style="font-size:12.8px"><span style="font-size:12.8px">FROM ordertable</span></div><div style="font-size:12.8px">order by custid;</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 24, 2016 at 11:50 AM, John Lange <span dir="ltr">&lt;<a href="mailto:john@johnlange.ca" target="_blank">john@johnlange.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What Adam said; something like:<div><br></div><div><span style="font-size:12.8px">SELECT custid, (select count(*) FROM ordertable where TTL=X), (select count(*) FROM ordertable where TTL=Y)</span><br style="font-size:12.8px"><span style="font-size:12.8px">FROM ordertable</span></div><div>order by custid;</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Mar 24, 2016 at 9:21 AM, Adam Thompson <span dir="ltr">&lt;<a href="mailto:athompso@athompso.net" target="_blank">athompso@athompso.net</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div>Subqueries:<br>
SELECT (SELECT ...), (SELECT ...) FROM ...<br>
<br>
If they don&#39;t work, upgrade to a newer version of MariaDB.  (If this is the customer I assume it is, use RackSpace&#39;s IUS repo to upgrade).<br>
<br>
Alternately, create two VIEWs, one for each aggregate count, and OUTER JOIN them.<br>
-Adam<br>
<br><br><div class="gmail_quote"><span>On March 24, 2016 9:16:31 AM CDT, Trevor Cordes &lt;<a href="mailto:trevor@tecnopolis.ca" target="_blank">trevor@tecnopolis.ca</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<pre><span>Can anyone help me figure out how to do this in SQL (MySQL)?<br><br>(pseudo-code giving you the gist):<br><br>SELECT custid, (count orders where ttl=X), (count orders where ttl=Y)<br>FROM ordertable<br>GROUP BY custid;<br><br><br>I basically want to count two different things based on two different <br>wheres.  If I put in a where clause then I select either the X or the Y <br>but I can&#39;t seem to get both in such a way I can count the X&#39;s and Y&#39;s.  I <br>tried thinking about unions but couldn&#39;t make it work.  I want to do this <br>all in 1 query as I want the sorted union of all custid&#39;s (X and Y).<br><br>P.S. ordertable has/can have multiple entries for each custid.<br><br>Ideas are appreciated!<br><hr><br></span><span>Roundtable mailing list<br><a href="mailto:Roundtable@muug.mb.ca" target="_blank">Roundtable@muug.mb.ca</a><br><a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br></span></pre></blockquote></div><span><font color="#888888"><br>
-- <br>
Sent from my Android device with K-9 Mail. Please excuse my brevity.</font></span></div><br></div></div>_______________________________________________<span class=""><br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca" target="_blank">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" rel="noreferrer" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
<br></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>John Lange<br><a href="http://www.johnlange.ca" target="_blank">www.johnlange.ca</a></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">John Lange<br><a href="http://www.johnlange.ca" target="_blank">www.johnlange.ca</a></div>
</div>