Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Subquery Totals

Author  Topic 

dimoss
Yak Posting Veteran

52 Posts

Posted - 2007-07-17 : 11:55:17
Hi,

I use the following query in my stats page to find the unique visitors and the pages they visited per day in a given month.

SELECT
CONVERT(CHAR(10),LogDate,103) As Date_,
Count(DISTINCT LogRemote_Addr) As Visitors,
Count(Lid) As Pages
FROM Log
WHERE LogMonth=7
Group by CONVERT(CHAR(10),LogDate,103)
ORDER BY CONVERT(CHAR(10),LogDate,103)

I would like to have the totals (Sum) of the "Visitors" and "Pages" also for the given month.
I think I have to use a subquery to accomplish that but I can't figure it out. I would appreciate your help.
Thanks,

www.tabletennis.gr

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-17 : 12:06:20
Please post some sample data and expected output.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

dimoss
Yak Posting Veteran

52 Posts

Posted - 2007-07-17 : 12:12:09
Ok. I have the following fileds.
LogDate = date of visit
LogRemoteAddr = ip of the visitor
Lid = a common id (autonumber)

The example

Lid LogDate LogRemoteAdd
1 15/7/2007 85.82.141.1
2 15/7/2007 85.82.141.1
3 15/7/2007 85.21.140.58
4 16/7/2007 85.21.140.58
5 16/7/2007 193.54.147.1
6 17/7/2007 193.57.100.1

This set according to my query will produce

Date Visitors Pages
15/7/2007 2 3
16/7/2007 2 2
17/7/2007 1 1

I would like to take also the Sum of Visitors and Pages which is 5 and 6 correlatively.

I think it's more clear now.
Thanks

www.tabletennis.gr
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-17 : 12:19:51
Dupe http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86490


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -