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

Koteswararao MallisettiRank #2,740 · 511 reputationPosted Oct 14, 2010, 5:37 AM EDT
the having is use along with group bu only
Kalyan Vedantam108 reputationPosted Oct 14, 2010, 6:26 AM EDT
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
Syed Arbab Ahmed88 reputationPosted Oct 14, 2010, 10:24 PM EDT
"...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.
Syed Arbab Ahmed88 reputationPosted Oct 14, 2010, 10:50 PM EDT
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.