I am working on implementation for a SQL which should display results with Union operation between Where and Having Clause. For example,
Select * from table where col1= 'get' group by col2 (OR/UNION) having avg(col3) >30 . This is not valid but trying to give use a case
The purpose of the sql statement is to return result set which satisfies both where and having conditions.
Lets say I have a table1, has with col1, col2, col3, col4 and large data in the table. Now, There is a use case in which user wants to see results when selects filters with specific crtieria col1 ='Y', avg(col2) >10, avg(col3*col4) =30 in filters list. Now, I have to create a criteria, such that, I should return all results which satisfies col1 ='Y' OR avg(col2) >10 OR avg(col3*col4) =30 , like we do in where clause with OR operator but here we have both where clause and having clause –
Like, the below query
resultset1 <= select * from table1 where col1= 'get'; resultset2 <= select * from table1 group by col2 having avg(col3) >30
final results = resultset1+ resultset2 Do any one have better approach or ideas in implementing such scenario?
Lets say I have filters combinations as below
col1 =23 OR avg(col2) >30 AND avg(col3) =10 OR avg(col1) <10 AND col2 =10
I need to display results satisfying these criteria in SQL