Hi!
'Having' can be used without 'Group by' as well, table has the data but this query is not returning any answers is there anything wrong with this query?
SELECT SUM(ACCOUNT_TYPE)
FROM TBLCUSTCHANNEL
HAVING SUM(ACCOUNT_TYPE) <=10
Please do guide in Oracle and in SQL.
Thanks in advance
Loading
Syed Arbab AhmedPosted Oct 15, 2010, 2:50 AM
2-That's the thing that I don't want to use 'GROUP BY' as from this website i found that
"...the HAVING clause may or may not include the GROUP BY clause. The syntax for HAVING is..."
http://www.1keydata.com/sql/sqlhaving.html
the query is not giving any syntax error, i want to know is there any logical error in that.
Syed Arbab AhmedPosted Oct 15, 2010, 2:24 AM
"...the HAVING clause may or may not include the GROUP BY clause. The syntax for HAVING is...."
http://www.1keydata.com/sql/sqlhaving.html
so I was trying to practice that.
Kalyan VedantamPosted Oct 14, 2010, 10:26 AM
The result of your query is just one row with a single value which is the sum of all the Account_Type. Now if this value is not <= 10 you will not get back anything.
You need to select an Id or some other field associated with the Account_Type and do a group by on that field. for e. let us say you have an Id field your query will be:
SELECT Id, SUM(ACCOUNT_TYPE)
FROM TBLCUSTCHANNEL
Group By Id
HAVING SUM(ACCOUNT_TYPE) <=10
Koteswararao MallisettiPosted Oct 14, 2010, 9:37 AM
the having is use along with group bu only