473,322 Members | 1,425 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,322 software developers and data experts.

SQL question ( retrieving records based on a priority order )

Hi all,

I have a table with this structure:

Customer ID | Transaction date | Transaction type
1 | 1/2/2008 | F
1 | 1/4/2007 | M
1 | 1/2/2008 | R
2 | 1//5/2007 | M
2 | 1/6/2007 | R
For each customer ID, I need to retrive only the records with the most
recent transaction date, and I did:

Customer ID | Transaction date | Transaction type
1 | 1/2/2008 | F
1 | 1/2/2008 | R
2 | 1/6/2007 | R

The problem is, each customer can make more than one transaction in
the same day (see above). In these cases, I need to retrieve only one
record per customer, based on the importance of the transaction: F is
more "important" than R which is more "important" than M. So, in the
example above, I would only retrieve transaction F for customer 1 and
disregard transaction R: they were made on the same date, but I am
more interested in F than in R.

Do you have any suggestions on how I could achieve this in SQL?

I use Microsoft SQL server 2005.

Thank you for your help!
Feb 22 '08 #1
1 1903
Thank you all for your precious tips!
Feb 24 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tilak.negi | last post by:
We have one single hash (#) table, in which we insert data processing priority wise (after calculating priority). for. e.g. Company Product Priority Prod. Qty Prod_Plan_Date C1...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
2
by: VB Programmer | last post by:
I am interested to hear your suggestions on this... I have a table full of survey questions. The questions are individually classified as priority 1, 2 or 3. (Priority 1 means the question...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
5
by: himilecyclist | last post by:
I have a query screen where the user has an option to search by name fields in the database. There are first, middle and last name fields and the results returned should be sorted last, first,...
4
by: virtualgreek | last post by:
Dear All, First of all I would like to take the time to thank you all for your efforts and time spent at this wonderful forum. I have found it very helpful with numerous examples available for...
9
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows()...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.