which records are included in the sum
-
Hello, I have the following sql SELECT stocksymbol,tradedate, sum(qty ) FROM TradingTransactions where stocksymbol="HINDALCO" group by stocksymbol,tradedate having sum(qty)>1000 In the above query I get the SUM of qty but how do I know which records or record Nos were selected. Thanks Pritha
-
Hello, I have the following sql SELECT stocksymbol,tradedate, sum(qty ) FROM TradingTransactions where stocksymbol="HINDALCO" group by stocksymbol,tradedate having sum(qty)>1000 In the above query I get the SUM of qty but how do I know which records or record Nos were selected. Thanks Pritha
Just look at the where and having clauses. It is very exact actually. If you want to see which records were used, just run the query without the where and having clauses, and without the sum function, export the whole thing to Excel, and perform the same logic there, using subtotals and auto filters.
My advice is free, and you may get what you paid for.
-
Just look at the where and having clauses. It is very exact actually. If you want to see which records were used, just run the query without the where and having clauses, and without the sum function, export the whole thing to Excel, and perform the same logic there, using subtotals and auto filters.
My advice is free, and you may get what you paid for.
-
thanks for your reply So do you mean to say that I cant know which records were included in the function through SQL in my database .And will have to go to Excel to find the same. Pritha
I think that maybe I do not understand your question. The where clause determine which records are included and the having clause determines that you don't want to see any dates which' records do not add up to (at least) 1000. That is simple and clear logic. So if you suspect that this query is not giving you the desired result, you can use Excel as a tool to check the outcome, and visually see each single record.
My advice is free, and you may get what you paid for.