473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Select Max Column - Query

1
This is probably a general SQL question but since I am dealing w/ DB2 I figured I would ask here.

I have a table with customer transaction information. The primary keys are cust_id and date (transaction data that is). The trasactions can be later modified and this causes for the field TRANS_SQ to auto increment. What I want to do is query for the rows that pertain to a particular transaction but hold the highest TRANS_SQ value.

Below is a sample from the table. Basically the result from the query should en up in the following rows being selected:

1, 4, 6, 10, 11 and 12

ROW_NUM CUST_ID SERVICE_DATE TRANS_TYPE TRANS_SQ X_VALUE
1 67850 1/31/2007 1 3 xxx
2 67850 1/31/2007 1 2 xxx
3 67850 1/31/2007 1 1 xxx
4 67850 2/28/2007 1 2 xxx
5 67850 2/28/2007 1 1 xxx
6 67850 3/31/2007 1 4 xxx
7 67850 3/31/2007 1 3 xxx
8 67850 3/31/2007 1 2 xxx
9 67850 3/31/2007 1 1 xxx
10 68749 8/31/2006 1 1 xxx
11 68749 9/30/2006 1 1 xxx
12 68749 10/1/2006 1 1 xxx


Thanks in advance for your help. And sorry for the ill formatted table.

Oscar
Apr 26 '07 #1
1 5593
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. SELECT First(ROW_NUM], CUST_ID, SERVICE_DATE, TRANS_TYPE, Max(TRANS_SQ), X_VALUE
  2. FROM TableName
  3. GROUP BY CUST_ID, SERVICE_DATE, TRANS_TYPE,  X_VALUE
Apr 26 '07 #2

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

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
2
by: Benoit Le Goff | last post by:
Hello. I test some query on sql server 2000 (sp2 on OS windows 2000) and i want to know why a simple query like this : select * from Table Where Column like '%value' is more slow on 2000 than...
3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
1
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in...
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
1
by: steveyell | last post by:
Hi there, I have a database with 90,000 property records and I need to split the database into 5 geographic areas. Those areas are defined by postcode districts, and a number of postcode...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.