Advertisement

07.21.2008 at 12:57PM PDT, ID: 23583202
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

grouping vs detailed, still very problematic

Asked by dbaSQL in MS SQL Server

I posted this question quite some time ago, but unfortunately, the problem persists:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23472149.html

Very long story short, this report is done on a certain type of trade, called an 'strade'.  The 1st query is a detailed report of all strades.  The 2nd query is a summation of the detailed report.  For example, if 1st report includes 50 trades for userA, 10 of which were 'strades', then the summation will be the volume of the 50 totaltrades, along with the volume and count of the 10 strades.  

It has come to my attention that some of them are correct, others are reported inaccurately.  For example, this one is coming back as 16 strades, when it should be 7.  

First query returns 7 records:
SELECT DISTINCT b.EndPoint,b.UserID AS BUserID,b.AcctID AS BAcctID,s.UserID AS SUserID,s.AcctID AS SAcctID,b.Symbol,b.Quantity, b.Price,
CONVERT(VARCHAR(10),b.timefield,101)+' '+SUBSTRING(CONVERT(VARCHAR(20),b.timefield,100),13,7) AS TradeTime
FROM database.dbo.strades b WITH (NOLOCK)
INNER JOIN database.dbo.strades s WITH (NOLOCK)
  ON b.endpoint = s.endpoint
  AND b.Quantity = s.Quantity
  AND b.Price = s.Price
  AND b.tradetime = s.tradetime
  AND b.side = 'B'
  AND s.side = 'S'
AND b.endpoint = 'cccc' and b.Userid = 'abc' and b.symbol = 'ymu8'
ORDER BY EndPoint,BUserID,b.Symbol

endpoint   buserid       bacctid    suserid         sacctid    s.symbol   s.qty   s.price, s.time
cccc    abc     0814    CH      08139      YMU8      1   12169.00000000      06/17/2008  2:24PM
cccc    abc      08142    JR      08139      YMU8      1   12167.00000000      06/17/2008  2:39PM
cccc   abc      08142   JR      08139      YMU8      1   12169.00000000      06/17/2008  2:21PM
cccc  abc      08142   JR      08139      YMU8      1   12195.00000000      06/17/2008 11:33AM
cccc  abc      08142   JR      08139      YMU8      1   12213.00000000      06/17/2008 12:24PM
cccc   abc      08142   JR      08139      YMU8      1    12221.00000000      06/17/2008 10:29AM
cccc   abc      08142   JR      08139      YMU8      1   12255.00000000      06/17/2008  9:34AM

Second one does a summation on the results of the first, yet it gives a total count of 16, instead of the 7 identified in query #1 :

SELECT b.endpoint,b.userID,b.Symbol,SUM(b.quantity)AS STradeVol,COUNT(*) AS TotalSTrades
  FROM database.dbo.strades b WITH (NOLOCK)
   INNER JOIN database.dbo.strades s WITH (NOLOCK)
        ON b.endpoint = s.endpoint
      AND b.Quantity = s.Quantity
        AND b.Price = s.Price
        AND b.tradetime = s.tradetime
        AND b.side = 'B'
      AND s.side = 'S'
AND b.endpoint = 'cccc' aND b.userID = 'abc' and b.symbol = 'YMU8'
     GROUP BY b.endpoint,b.userID,b.Symbol

endpoint     userid         symbol        stradeVolume         totalSTrades
cccc           abc             YMU8      16      16      

Why do these two queries produce different resultsets?    The first details 7 records, the count in the summation should be 7, not 16.Start Free Trial
[+][-]07.21.2008 at 01:28PM PDT, ID: 22054033

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: joechina
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.21.2008 at 03:18PM PDT, ID: 22054848

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628