Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query help - sum & group 1

Status
Not open for further replies.

teroy

Programmer
Oct 17, 2000
67
AU
Hi guys,
I have records that look like the following
Code:
 custname |   custgroup   |  queryname  |    subnet    | day | hour |  dbytes  | ubytes
----------+---------------+-------------+--------------+-----+------+----------+--------
 cee      | SOHO DSL User | chargeddata | 202.137.73.2 |   1 |    0 |    53516 |      0
 cee      | SOHO DSL User | chargeddata | 202.137.73.2 |   1 |    1 |    54703 |      0
 cee      | SOHO DSL User | chargeddata | 202.137.73.2 |   1 |    2 |    52161 |      0
 cee      | SOHO DSL User | chargeddata | 202.137.73.2 |   1 |    3 |    58765 |      0
 cee      | SOHO DSL User | chargeddata | 202.137.73.2 |   1 |    4 |    58648 |      0


In queryname there is values called chargeddata and proxydata. i would like to get a sum of the downloaded amounts from these 2 values across each hour per day.

i have the following SQL which only adds the chargeddata amount and not the proxydata

Code:
select day,hour,sum(dbytes) 
from custresults_200311 
where custname='cee' 
and (queryname='chargeddata' or queryname='proxydata') group by day,hour

Any help would be much appreciated
 
If you're trying to get the sums for chargeddata and proxydata independently, you'd also need to group on the queryname field.

[tt]SELECT queryname,day,hour,sum(dbytes) FROM custresults_200311 WHERE custname='cee' and (queryname='chargeddata' or queryname='proxydata') GROUP BY queryname,day,hour[/tt]

You won't get any result for one of the querynames if there are no rows with data for it, though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top