I have a table named Bills (BillID is the Primary Key):
and want an output that selects the last date and its corresponding amount grouped by company id:
I started with
which selects the correct "LastDate" of each CompanyID. However, I can't seem to include the Amount column. How do I make my SELECT statement include the Amount column?
Code:
BillID CompanyID Date Amount
-- -------- ------ -------
1 10001 01/01/06 100.00
2 10001 02/20/06 200.00
3 10002 01/05/06 5993.21
4 10002 02/22/06 245.20
5 10002 03/24/06 336.28
6 10003 01/22/06 123.45
and want an output that selects the last date and its corresponding amount grouped by company id:
Code:
CompanyID LastDate Amount
---------- ---------- -------
10001 02/20/06 200.00
10002 03/24/06 336.28
10003 01/22/06 123.45
I started with
Code:
SELECT CompanyID, MAX(Date) as LastDate FROM Bills GROUP BY CompanyID
which selects the correct "LastDate" of each CompanyID. However, I can't seem to include the Amount column. How do I make my SELECT statement include the Amount column?