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 Mar 15, 2011, 1:49 AM
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.
???
Raja KrishnamurthyPosted Mar 9, 2011, 9:51 AM
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
andrey robianesPosted Mar 9, 2011, 9:29 AM
SELECT SUM(salary)

FROM employees
HAVING SUM(salary) >=10
result:
Syed Arbab AhmedPosted Mar 7, 2011, 2:18 AM
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.
Suthish NairPosted Feb 28, 2011, 1:33 PM
andrey robianesPosted Feb 28, 2011, 11:42 AM
for the other syntax using just WHERE clause,,
Syed Arbab AhmedPosted Oct 15, 2010, 3:12 AM
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.
Manikavelu VelayuthamPosted Oct 14, 2010, 8:45 AM
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