DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

Help! Display 1 row showing total records with GROUP BY

rated by 0 users
This post has 2 Replies | 0 Followers

Top 100 Contributor
Posts 10
Points 245
mbernardo Posted: 05-18-2006 8:54 AM

Help! Consider the following table:

Sub_ID   Aff_ID   Entry_date   Clicks
-------------------------------------
33 232 5/1/2006 1
42 422 5/2/2006 1
33 83 5/2/2006 3
76 333 5/3/2006 1
... and so on

I have the following statement in SQL Query Analyzer:

SELECT count(*) as counter
FROM Ad_Stats_Table
WHERE Aff_ID = 33 AND (Entry_Date between '5/1/2006' and  '5/16/2006')
Group By Sub_ID

That query returns 35,830 rows. But it returns the following:

counter
-------
1
1
1
1
... (35,830 times!)

I want it to return just 1 row containing the row count like so:

counter
-------
35830

Can someone help?

http://www.filipino.ca http://www.uniqual.ca
  • | Post Points: 35
Top 10 Contributor
Posts 1,969
Points 39,350

Try This:

[code language="T-SQL"]

select count(*)
from Ad_Stats_Table
Where
Sub_ID = 33
And
( entry_date
 between '5/1/2006' and  '5/16/2006')
Group By Sub_ID

[/code]

or you can also group it by aff_id

[code language="T-SQL"]

[/code]

select count(*)
from Ad_Stats_Table
Where
Aff_ID = 333
And
( entry_date
 between '5/1/2006' and  '5/16/2006')
Group By Aff_ID

devpinoy sig

  • | Post Points: 5
Top 10 Contributor
Posts 1,100
Points 17,955
the group by is messing your needs, why do you need it, select count(*) will do it with your filter
  • | Post Points: 5
Page 1 of 1 (3 items) | RSS

Copyright DevPinoy 2005-2008