I'm trying to display three different columns in SQL all from the same database but each from different tables. One is called Name which I would also like to have the output grouped by, another column is a calulation between two columns called Money, and the third column is Date. NameId is what connects Name and the Money Column, and MoneyId connects Money to Date
I'm creating this on dbVisualizer, The three columns are all parts of different tables inside the same database. How can I display the calculated Money coulmn with its correct date, while being grouped by the Name Column
I know this is incorrect but it's what I have so far. How can I have the money calculation but not have to throw it's attributes in the group by function for it to run.
Select A.Name,
MAX(B.BillsPaid)As Paid,
MAX(B.BillsSent) As Sent, C.DateId As Date_Id,
-- This is the money Calculation
(CAST(BillsPaid As decimal(5,0))/CAST(nullif(BillsSent, 0) As
decimal(5,0)))
* 100 as Money
From B
Inner Join A on B.NameId = A.NameId
Inner Join C on B.MoneyId = C.MoneyId
Group By A.Name, C.DateId, B.BillsPaid, B.BillsSent
I would like to see this in the display. I'm new to SQL so all help is highly appreciated, thank you.
Name Money(%) Date
John Doe 87% June 2019
Instead I see
Name Paid Sent Money Date
John Doe 2 4 50% June 2019
John Doe 1 4 25% June 2019
John Doe 3 4 75% July 2019
I want the money to be grouped by each name, for each date, however each name has more then one paid/sent per month