Solved

# Tricky Group by with Sort?

Posted on 2008-06-13
173 Views
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
Frontdoor.com  25
Listing 1256
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
Question by:jfergy
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 19

Expert Comment

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

Author Comment

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

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

ID: 31467103
Thanks that was awesome!
0

LVL 19

Expert Comment

ID: 21800455
thanks, you're welcome
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.