HI
I have three tables
- equtable = car main data
- mainttable = maintenance
- rentaltable = rental
i create custom view to show me for each car total maintenance , total rental and total profit
##############################################
SELECT equtable.ID,
equtable.EQU_TYPE,
equtable.EQU_MARK,
equtable.SN,
equtable.PN,
equtable.COLOR,
equtable.YEAR,
Sum(DISTINCT rentaltable.MONTHLYRATE) AS RentCost,
Sum(DISTINCT mainttable.AMOUNT) AS MaintCost,
(rentaltable.MONTHLYRATE - mainttable.AMOUNT) AS Amount
FROM rentaltable
INNER JOIN equtable ON equtable.SN = rentaltable.SN AND equtable.EQU_TYPE =
rentaltable.EQU_TYPE
INNER JOIN mainttable ON equtable.PN = mainttable.PN AND equtable.SN =
mainttable.SN
GROUP BY equtable.ID,
equtable.EQU_TYPE,
equtable.EQU_MARK,
equtable.SN,
equtable.PN,
equtable.COLOR,
equtable.YEAR,
(rentaltable.MONTHLYRATE - mainttable.AMOUNT)
#################################################
issues:
first one incase that one of these tables for example retaltable just i insert 1 record = 10000 and
the maintable i insert 3 records = 500 / 300 / 500 its will show in custom view two times 10000 and the total profit show = 19200
but the correct profit = 8700
its confused me
the second issue is when one of these tables for example retaltable i have not insert any record and the mainttalbe insert 1 record
so when i need to view the total profit its show me "no records found" even when i change the tables
third thing
how i can get the data from retaltable to show it in invoice to print it