473,513 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SUM function with conditions (>) or (<)

seraieis
60 New Member
Hello everyone!

I've run into a little snag with SQL (which I am still very new at). What I'm trying to do it run a query again medical claim information and return only claims where the total is over $1,000. There can be multiple lines per claim

i.e.:
CLAIM_ID, PAY_AMT
1, 1000
2, 50
2, 50
3, 900
3, 100

Here is the query:
Expand|Select|Wrap|Line Numbers
  1. SELECT MBR_NUM, CLAIM_ID, SUM(PAY_AMT) AS SUMOF_PAY_AMT
  2. FROM CLAIM
  3. WHERE SUMOF_PAY_AMT > 1000.00
  4. GROUP BY MBR_NUM, CLAIM_ID
  5.  
When I run this, it gives me this error:
Expand|Select|Wrap|Line Numbers
  1. ERROR [42S22][IBM][CLI Driver][DB2] SQL0206N "SUMOF_PAY_AMT" is not valid in the context where it is used. SQLSTATE=42703
Any ideas as to what I'm doing wrong?

Thanks!
Aug 13 '08 #1
2 9064
seraieis
60 New Member
It's truely gratifying to solve your own problem :)

Expand|Select|Wrap|Line Numbers
  1. SELECT MBR_NUM, CLAIM_ID, SUM(PAY_AMT)
  2. FROM CLAIM
  3. WHERE ACCT_NUM='3001416'
  4. GROUP BY MBR_NUM, CLAIM_ID
  5. HAVING SUM(PAY_AMT) > 1000
  6.  
I didn't understand anything about the HAVING clause.
Aug 13 '08 #2
ganeshmn25
28 New Member
Hi dude,

We need to avoid WHERE Clause while using GROUP BY Clause , Instead we can use HAVING clause that will be act as WHERE clause for checking aggregate functions

Query :
-----------

SELECT MBR_NUM, CLAIM_ID, SUM(PAY_AMT)
FROM CLAIM
GROUP BY MBR_NUM, CLAIM_ID
HAVING SUM(PAY_AMT) > 1000


Regards

Padmanaban.N
DB2 Database Associate
Aug 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2501
by: SAN CAZIANO | last post by:
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't...
1
4248
by: Leila | last post by:
Hi folks, I have a fairly complex xml document which looks like this: <my:InsideView xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-02T14:22:59" xml:lang="en-us">...
4
6887
by: Leila | last post by:
Hi, I am having a problem retrieving the html tags from my XML document when it's being loaded into a DOM object. For example, my xml contains the following: <my:InsideView> .. ..
2
3185
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
10538
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
34
10972
by: Mark Moore | last post by:
It looks like there's a pretty serious CSS bug in IE6 (v6.0.2800.1106). The HTML below is validated STRICT HTML 4.01 and renders as I would expect in Opera, FrontPage, and Netscape. For some...
11
13658
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
1
3480
by: chuck | last post by:
Hi, I have a php function creating links from a products mysql database. some of the descriptions have characters that I need to escape but whatever i do, javascript doesn't like them. for...
8
1323
by: Aaron | last post by:
Hello, I have this portion of code: <xsl:value-of select="substring(Body,1,400)" disable-output-escaping="yes" /> Is it possible to code it to stop when it reads the first &lt;/p&gt; instead of...
5
2255
by: test | last post by:
Code: a = document.createTextNode("< somestring >"); ....will transform < into &lt; and > into &gt; When I want to read that node later, I can only get it back in this form: "&lt; somestring &gt;" ...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.