rantsh Posted February 14, 2007 Share Posted February 14, 2007 Hi all, I want to do a select with 2 counts of the same column, one of them should be where column1>0 and the other has to be a count regardless of the value. Anyone can tell me if this is possible? Thx, Roderick Quote Link to comment Share on other sites More sharing options...
fenway Posted February 14, 2007 Share Posted February 14, 2007 It's a little tricky... I've cheated before with SUM(), basically using a 0 or 1 to fake the counts for the conditional one. Quote Link to comment Share on other sites More sharing options...
rantsh Posted February 14, 2007 Author Share Posted February 14, 2007 someone at the mysql forum posted a reply to this same Q (I asked both here and there) the reply was select count(column1) allrows, count case when column1>0 then 1 else null end as somerows from yourtablename Has someone tried this out before? I'll try in a while and let you know though Quote Link to comment Share on other sites More sharing options...
fenway Posted February 14, 2007 Share Posted February 14, 2007 Sure, that will work just as well... I was thinking something along the lines of: select count(column1) allrows, SUM( IF(column1>0,1,0 ) ) as somerows from yourtablename Quote Link to comment Share on other sites More sharing options...
rantsh Posted February 14, 2007 Author Share Posted February 14, 2007 I must say both solutions work like a charm, thanks for your help (and to Guelphdad from the mysql forum) Quote Link to comment Share on other sites More sharing options...
artacus Posted February 15, 2007 Share Posted February 15, 2007 Doubt with a Select I think the doubt clause has been deprecated since version 5.0.4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.