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

Select unique

We have a transaction record that, for the sake of brevity, I will use
a simple paradigm to convey my need:

A sales clerk sells several pairs of shoes over the period of a day,
each & every day the clerk works. Each transaction is recorded in
a database. All clerks use a single physical register but login to
capture unique ID. As each clerk logs in, it automatically logs out
the prior user and writes a zero-dollar record.

Each record logs the RcdNbr, clerk's ID, date-timestamp and sales
amount. (Other fields not pertinent to this discussion)

Example:
Rcd...CID...yyyy-mmdd.hhmm...Sale
001...ABC...2005-0101.0850...10.00
002...ABC...2005-0101.0930...00.00
003...DEF...2005-0101.1000...15.51
004...DEF...2005-0101.1200...00.00
005...ABC...2005-0101.1300...12.83
006...ABC...2005-0101.1530...00.00

The above is unsorted. I would first sort by CID (ClerkID) to get:

Rcd...CID...yyyy-mmdd.hhmm...Sale
001...ABC...2005-0101.0850...10.00
002...ABC...2005-0101.0930...00.00
005...ABC...2005-0101.1300...12.83
006...ABC...2005-0101.1530...00.00
003...DEF...2005-0101.1000...15.51
004...DEF...2005-0101.1200...00.00

As a double-check of a clerk's actual worked hours we want to extract
the last record for each clerk for each day. In the above sample, I'd
need records 004 & 006.

The transaction file covers 6 months worth of data.

Is there a statement that I can construct that would extract the last
(greatest?) time for each clerk for each day?

Aug 25 '05 #1
1 5737
Something like this?

select
CID,
convert(char(8), tmstamp, 112) as 'Day',
max(tmstamp) as 'Last Logout'
from
dbo.SomeTable
group by
CID,
convert(char(8), tmstamp, 112)
order by
'CID', 'Day'

Simon

Aug 25 '05 #2

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

Similar topics

1
by: MePadre | last post by:
To all, I am hoping for some insight in to this query. I have a homepage on my Intranet that displays the three most recent postings for a number of categories (i.e. announcements, discussion...
0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
9
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my...
4
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the...
5
by: Antanas | last post by:
Hi folks. I need unique sequence object generated for each row returned form select statement. Here is my ADDID() UDF: CREATE FUNCTION DB2ADMIN.ADDID() RETURNS CHAR(6) NOT DETERMINISTIC F1:...
2
by: Marcel Hug | last post by:
Hi NG! With a Inner-Join SQL I get my datas in a DataSet. In the table are the column Entry and Version. Like this: Entry Version 1 1 1 2 1 ...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
0
by: kaapie | last post by:
Oracle does not know which table's rowid to return from this view and thus it gives an error. What this means is that one of the underlying tables in the view has to have either a primary key or...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.