E
Erick C
Hi everybody. I am having a problem with a query that I am working
on.
I have a table containing customer names, trade dates, and dollar
amounts. Customers can have multiple trades on the same day,
sometimes even the same dollar amount. I want to have the table
sorted by name, date, then dollars so the query pulls everything in
from lowest/earliest to highest/latest.
I was trying to make a query that pulled in the customer name and
trade dates, then added a new column called "Row" that had the record
number. I want the query to show all names and dates, since there are
duplicate dates, and assign a record number to each record. The
number should start over at each change in date. So the final result
will look something like below:
(New Field)
Name Date Row
Bob Smith 1/1/10 1
Bob Smith 1/5/10 1
Bob Smith 1/5/10 2
Bob Smith 1/5/10 3
Bob Smith 2/1/10 1
Joe Johnson 1/1/10 1
My SQL is currently counting the names and dates, and where there is a
duplicate date it will not show each date individually. Instead it
shows the customer name and date once with a record count in the row
field. So using my example above, I only get one record for Bob Smith
on 1/5/10 and the Row has 3. I want to get 3 individual records
showing 1/5/10 three times and the row to show 1,2, and 3
respectively.
Here is the SQL that I have been messing with. Any help would be
greatly appreciated.
SELECT tbl_Nov_Maturities.[Name], tbl_Nov_Maturities.[Trade Date],
(SELECT Count(*) FROM [tbl_Nov_Maturities] AS [XX] WHERE [XX].[Name]
=[tbl_Nov_Maturities].[Name] AND [XX].[Name] & [XX].[Trade Date]<
[tbl_Nov_Maturities].[Name] & [tbl_Nov_Maturities].[Trade Date]) AS
Row
FROM tbl_Nov_Maturities
GROUP BY tbl_Nov_Maturities.[Name] & tbl_Nov_Maturities.[Trade Date],
tbl_Nov_Maturities.[Name], tbl_Nov_Maturities.[Trade Date];
on.
I have a table containing customer names, trade dates, and dollar
amounts. Customers can have multiple trades on the same day,
sometimes even the same dollar amount. I want to have the table
sorted by name, date, then dollars so the query pulls everything in
from lowest/earliest to highest/latest.
I was trying to make a query that pulled in the customer name and
trade dates, then added a new column called "Row" that had the record
number. I want the query to show all names and dates, since there are
duplicate dates, and assign a record number to each record. The
number should start over at each change in date. So the final result
will look something like below:
(New Field)
Name Date Row
Bob Smith 1/1/10 1
Bob Smith 1/5/10 1
Bob Smith 1/5/10 2
Bob Smith 1/5/10 3
Bob Smith 2/1/10 1
Joe Johnson 1/1/10 1
My SQL is currently counting the names and dates, and where there is a
duplicate date it will not show each date individually. Instead it
shows the customer name and date once with a record count in the row
field. So using my example above, I only get one record for Bob Smith
on 1/5/10 and the Row has 3. I want to get 3 individual records
showing 1/5/10 three times and the row to show 1,2, and 3
respectively.
Here is the SQL that I have been messing with. Any help would be
greatly appreciated.
SELECT tbl_Nov_Maturities.[Name], tbl_Nov_Maturities.[Trade Date],
(SELECT Count(*) FROM [tbl_Nov_Maturities] AS [XX] WHERE [XX].[Name]
=[tbl_Nov_Maturities].[Name] AND [XX].[Name] & [XX].[Trade Date]<
[tbl_Nov_Maturities].[Name] & [tbl_Nov_Maturities].[Trade Date]) AS
Row
FROM tbl_Nov_Maturities
GROUP BY tbl_Nov_Maturities.[Name] & tbl_Nov_Maturities.[Trade Date],
tbl_Nov_Maturities.[Name], tbl_Nov_Maturities.[Trade Date];