0

Each time I run the script it only gives me the MaxDate(Latest date) but a wrong balance figure. what I'm I missing? Here is the code I used;

select CustomerName,MAX(BalanceDate) AS MaxDate,Balance,"Credit Card" AS AccountType
from customer
INNER JOIN creditcardbalance ON customer.ID=creditcardbalance.CustID 
group by CustomerName
UNION
SELECT CustomerName,MAX(BalanceDate) AS MaxDate,Balance,"Bond" AS AccountType
from customer
INNER JOIN bondbalance ON customer.ID=bondbalance.CustID 
group by CustomerName
order by CustomerName;
nbk
  • 45,398
  • 8
  • 30
  • 47
Mariah
  • 1
  • UIr will be because oe of the queries doesn give any result, but without data, we can only speculate, so run bith queries seprate ly and see which has no rows that fit – nbk Feb 04 '22 at 13:37
  • select * from (your query order By BalanceDate Desc ) group by CustomerName. Also remove the Max(BalanceDate) & group it outside. – Kristo Feb 04 '22 at 13:51
  • what do you mean when you say I should remove the max(balancedate) and group it outside – Mariah Feb 04 '22 at 13:59

0 Answers0