Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SQL query help

Author  Topic 

noman0008
Starting Member

3 Posts

Posted - 2014-09-27 : 14:27:27
I know this can be done; but not sure how (maybe using co-related subquery):

a. Transform the following query using only SELECT, FROM, and WHERE:

SELECT product, SUM(quantity) AS TotalSales
FROM Purchase
WHERE price > 1
GROUP BY product
HAVING sum(quantity) > 30;

b. Do you think any SQL query written using GROUP BY and HAVING clauses can be transformed to a query which only uses SELECT, FROM, and WHERE?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-09-28 : 11:20:31
WITH cte AS ( your original query here without having)
SELECT * FROM cte where totalsales > 30



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -