ques1. sql’s where clause cant be used with aggregate functions(sum,avg, max,min) ?
ques2. Considering a table named cust, containing columns: orderno, custid, cost
select * from cust having cost> avg(cost)
avg(cost) gives output 5695 therefore, 3 records should come in the output since they have cost greater than 5695. But only one is coming. On the other hand this query:
select * from cust having cost>(select avg(cost) from cust) gives correct output why?
HAVINGGROUP BYBecause that is almost a correct query (see 2). It should be
select * from cust where cost>(select avg(cost) from cust)