Solved

Tricky Group by with Sort?

Posted on 2008-06-13
5
167 Views
Last Modified: 2010-04-21
Hello-

I have the following tables:
Personnel
ListingStats
Listings

I need to create a report for my personnel for their listings that gives them a break down of the stats and source count under each. So for example:

Listing 1234
 Google.com  154
 Frontdoor.com  25
Listing 1256
 Google.com 133
 Frontdoor.com 25

The listingStats table can have the source defined from anywhere on the web, so I wont be able to know what that source is, but I need to group by the source as a whole and the count. Your help is greatly apprecited. I have included the table breakdown below and possible query?

Select viewdate, source from tblListingStats where ListingID in(Select ListingID from tblListings where PersonnelID = ListingagentID) Groupby source, viewdate order by ListingID


0
Comment
Question by:jfergy
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:frankytee
ID: 21784504
post all the relevant fields from each table. for eg
which table does PersonnelID and ListingagentID come from?
0
 

Author Comment

by:jfergy
ID: 21795634
tblListingStats: ID, ListingID, DateTime, Source
TblPersonnel: PersonnelID, FirstName, LastName
tblListings: ListingID, PersonnelID

PersonnelID to tblListings is a 1 to Many relationship
ListingID to tblListingStats is a 1 to many relationship

Thanks for the help!
0
 
LVL 19

Accepted Solution

by:
frankytee earned 110 total points
ID: 21799416
try
select p.PersonnelID, l.ListingID,s.Source,
count(s.ID) as SourceCount
from TblPersonnel p join tblListings l
on p.PersonnelID = l.PersonnelID
join tblListingStats s
on l.ListingID = s.ListingID
group by p.PersonnelID, l.ListingID,s.Source

if that doesn't work then post sample data of each table and your query result set
0
 

Author Closing Comment

by:jfergy
ID: 31467103
Thanks that was awesome!
0
 
LVL 19

Expert Comment

by:frankytee
ID: 21800455
thanks, you're welcome
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now