In the usual case, this SQL
select count(*) from mytable where ...
returns an accurate count of the rows you want.
But how do I go about counting rows from this SQL (the sum...if
statements function as a pseudo pivot query)?
SELECT sum(IF(date_report = ('2005-06-30'),shares,0)) as 'Q2
2005',sum(IF(date_report = '2005-03-31',shares,0)) as 'Q1 2005' from
companies left join positions on co_id = positions_co_id where
positions_co_issue_id = 7194 AND date_report
in('2005-06-30','2005-03-31') group by co_id order by 'Q2 2005' DESC
In this case, I'll end up with a row count of, say, 360. When I try to
count the rows I come up with numbers way different. For instance, this try:
select count(co_id) from companies left join positions on co_id =
positions_co_id where positions_co_issue_id = 7194 AND date_report
in('2005-06-30','2005-03-31')
....might give me 1000, while this one...
select count( distinct co_id) from companies left join positions on
co_id = positions_co_id where positions_co_issue_id = 7194 AND
date_report in('2005-06-30','2005-03-31')
....might give me 320.
I'd sure appreciate any thoughts!
--Brent