Help? This is simple but I'm drawing a blank. Have a very small table, but
need specific data out of it. Here is the structure:
ClientID InvDate ItemAmt
001 3/7/03 $10
001 3/7/03 $20
001 5/8/04 $10
001 5/8/04 $3
002 5/9/04 $5
002 5/9/04 $2
I'm trying to make the query do two things. First is go through data set
and find items with "most recent or MAX date". Second, sum up items for a
that most recent date into a single line item total. Do I need to split
into 2 queries? Resultant set should look like this:
Client ID InvDate ItemAmt
001 5/8/04 $13
002 5/9/04 $7
Can anyone help with this? I'm drawing a blank. Thanks! 4 1722
Create two queries.
Q1:based on main table(T1)
Include ClientId, InvDate; convert to a Totals query;
Group By ClientId and set InvDate to max
Q2:
based on T1 and Q! joined on ClientId and Invdate = Max(Invdate)
Include Clientid, invdate and itemamt from T1.
Convert to a Totals query.
GroupBy ClientId and Invdate, set ItemAmt to Sum
Peter
MX1 previously wrote: Help? This is simple but I'm drawing a blank. Have a very small table, but need specific data out of it. Here is the structure:
ClientID InvDate ItemAmt 001 3/7/03 $10 001 3/7/03 $20 001 5/8/04 $10 001 5/8/04 $3 002 5/9/04 $5 002 5/9/04 $2
I'm trying to make the query do two things. First is go through data set and find items with "most recent or MAX date". Second, sum up items for a that most recent date into a single line item total. Do I need to split into 2 queries? Resultant set should look like this:
Client ID InvDate ItemAmt 001 5/8/04 $13 002 5/9/04 $7
Can anyone help with this? I'm drawing a blank. Thanks!
"MX1" <mx*@mx1.abc> wrote in message news:<TeLGc.3799$WX.2252@attbi_s51>... Help? This is simple but I'm drawing a blank. Have a very small table, but need specific data out of it. Here is the structure:
ClientID InvDate ItemAmt 001 3/7/03 $10 001 3/7/03 $20 001 5/8/04 $10 001 5/8/04 $3 002 5/9/04 $5 002 5/9/04 $2
I'm trying to make the query do two things. First is go through data set and find items with "most recent or MAX date". Second, sum up items for a that most recent date into a single line item total. Do I need to split into 2 queries? Resultant set should look like this:
Client ID InvDate ItemAmt 001 5/8/04 $13 002 5/9/04 $7
Can anyone help with this? I'm drawing a blank. Thanks!
ItemAmt is a number, right?
SELECT a.ClientID, a.InvDate, Sum(a.ItemAmt)
FROM TableX AS a
GROUP BY a.ClientID, a.InvDate
HAVING a.InvDate=
(SELECT max(invdate)
FROM TableX b
WHERE b.clientid=a.clientid
)
;
Thanks, I'll give this a try.
:)
"Theo Peterbroers" <pe*********@floron.leidenuniv.nl> wrote in message
news:39**************************@posting.google.c om... "MX1" <mx*@mx1.abc> wrote in message
news:<TeLGc.3799$WX.2252@attbi_s51>... Help? This is simple but I'm drawing a blank. Have a very small table,
but need specific data out of it. Here is the structure:
ClientID InvDate ItemAmt 001 3/7/03 $10 001 3/7/03 $20 001 5/8/04 $10 001 5/8/04 $3 002 5/9/04 $5 002 5/9/04 $2
I'm trying to make the query do two things. First is go through data
set and find items with "most recent or MAX date". Second, sum up items for
a that most recent date into a single line item total. Do I need to split into 2 queries? Resultant set should look like this:
Client ID InvDate ItemAmt 001 5/8/04 $13 002 5/9/04 $7
Can anyone help with this? I'm drawing a blank. Thanks!
ItemAmt is a number, right?
SELECT a.ClientID, a.InvDate, Sum(a.ItemAmt) FROM TableX AS a GROUP BY a.ClientID, a.InvDate HAVING a.InvDate= (SELECT max(invdate) FROM TableX b WHERE b.clientid=a.clientid ) ;
Thanks. Worked like a champ.
:)
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me**********************@russellscott.btinter net.com... Create two queries. Q1:based on main table(T1) Include ClientId, InvDate; convert to a Totals query; Group By ClientId and set InvDate to max
Q2: based on T1 and Q! joined on ClientId and Invdate = Max(Invdate) Include Clientid, invdate and itemamt from T1. Convert to a Totals query. GroupBy ClientId and Invdate, set ItemAmt to Sum
Peter MX1 previously wrote:
Help? This is simple but I'm drawing a blank. Have a very small table, but need specific data out of it. Here is the structure:
ClientID InvDate ItemAmt 001 3/7/03 $10 001 3/7/03 $20 001 5/8/04 $10 001 5/8/04 $3 002 5/9/04 $5 002 5/9/04 $2
I'm trying to make the query do two things. First is go through data set and find items with "most recent or MAX date". Second, sum up items for a that most recent date into a single line item total. Do I need to split into 2 queries? Resultant set should look like this:
Client ID InvDate ItemAmt 001 5/8/04 $13 002 5/9/04 $7
Can anyone help with this? I'm drawing a blank. Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Samantha Smit |
last post by:
Hi,
I am trying to create a simple asp page that has one command button that
updates a database. The URL of the page is like this:
http://MyServer.com/Update.asp?UserName=Tom
My asp code is...
|
by: Patchwork |
last post by:
Hi Everyone,
Please take a look at the following (simple and fun) program:
////////////////////////////////////////////////////////////////////////////
/////////////
// Monster Munch, example...
|
by: unixman |
last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to
posting in the newsgroups for help. :)
Simple problem, in theory.
Given table "map":
CREATE TABLE map (
entry_id...
|
by: j.mandala |
last post by:
I created a simple link between two tables in a query. TableA has
Social Security numbers stored as Long Integer Data. (I imported this
table).
The Join is between these two fields
Table ...
|
by: d.p. |
last post by:
Hi all,
I'm using MS Access 2003.
Bare with me on this description....here's the situation: Imagine insurance,
and working out premiums for different insured properties. The rates for
calculating...
|
by: Don Wash |
last post by:
Hi All!
I've been searching everywhere for a simple sample of producing a bar graph
using CrystalReport by specifying SQL Query, and I've found none of it! I
find so many complex samples with so...
|
by: John Baker |
last post by:
Hi:7
Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool
looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have
named HireInput,...
|
by: Fendi Baba |
last post by:
I created a person table with various fields such as Suffix,
Salutation, etc, Some of these fields may not be mandatory for example
suffix. In the actual table itself, I only have a field for...
|
by: Emin |
last post by:
Dear Experts,
I have a fairly simple query in which adding a where clause slows
things down by at least a factor of 100. The following is the slow
version of the query
...
|
by: rogynskyy |
last post by:
Hi guys,
I'm running MSDE 2000 A on Win XP
I've got a database with several tables, all of the tables display data in query manager.
I wrote this simple query:
Select
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
|
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...
|
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,...
| |