troubleshooting Question

MSSQL Query Join not Grouping

Avatar of CLupo
CLupo asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008
14 Comments1 Solution249 ViewsLast Modified:
Please refer to attached images for better explanation.  This is very difficult to articulate in words.  

Back story:  This query is for a restaurant loyalty system and tracking card members visits/ticket details.  

I have the query seen in before.png that is correctly joining all the tables and giving the information needed.  There is a count and a sum to show the total number of visits and amount spent.  The client wants to be able to limit the data to specific items sold within the tickets.  When I add in the table that contains the items sold per ticket it throws the numbers way off because the sum and count are treating the added table as a multiplier for each item sold see after.png.  I dont need any results from the added table I just need to include in the where statement a where itemid = 'XX'.

Any help greatly appreciated!  Please let me know if you need anymore information.
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros