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

Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 14, 2010, 4:45 AM EDT
Does the query throw any error ?
What output it generates ?
if the values is null, then there might be a row which the Account_type value is null.
becuase null + anything = null
While summing up, there should not be any row that contain null value.
you put like condition Where Account_Type IS NOT NULL
like below
SELECT SUM(ACCOUNT_TYPE)
FROM TBLCUSTCHANNEL WHERE ACCOUNT_TYPE IS NOT NULL
HAVING SUM(ACCOUNT_TYPE) <=10
Syed Arbab Ahmed88 reputationPosted Oct 14, 2010, 11:12 PM EDT
2-SUM(ACCOUNT_TYPE) column comes but without any data and i know that in table there is relevant data.
3-No Account_Type is 'NULL', in TBLCUSTCHANNEL there should be Account_Type.
andrey robianes4 reputationPosted Feb 28, 2011, 6:42 AM EST
for the other syntax using just WHERE clause,,
Suthish NairRank #92 · 22.8K reputationPosted Feb 28, 2011, 8:33 AM EST
Syed Arbab Ahmed88 reputationPosted Mar 6, 2011, 9:18 PM EST
SELECT SUM(ACCOUNT_TYPE)
FROM TBLCUSTCHANNEL
HAVING SUM(ACCOUNT_TYPE) <=10
giving this error:
Table or view does not exist.
& This query:
SELECT SUM(ACCOUNT_TYPE)
FROM TBLCUSTCHANNEL
where SUM(ACCOUNT_TYPE) <=10
giving this error:
Group function is not allowed here.
andrey robianes4 reputationPosted Mar 9, 2011, 4:29 AM EST
SELECT SUM(salary) FROM employees HAVING SUM(salary) >=10 result:Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 9, 2011, 4:51 AM EST
Based on the description of the table names and column name I think you want to get the Account_Types with less than 10 customers. If that is the case then the following query should help:
SELECT Account_Type, Count(Account_Type)
FROM TBLCUSTCHANNEL
GROUP BY Account_Type
Having Count(Account_Type) <=10
I apologize if my assumption is wrong.
HTH.
Happy Programming!!!
Regards,
Raja
Syed Arbab Ahmed88 reputationPosted Mar 14, 2011, 9:49 PM EDT
There was a logical error in my query as I wanted to use sum function for those account_type whose values are less than or equal to 10,
but the above query actually doing sum with all records of
account_type, and answer was not showing because there sum was above 10.
So either I have to use subquery or I don't know how much I can play with this query to have my desired result.
???