SQL SUM total using 2 tables -


i have 2 tables: tbl_equipments , tbl_proposal.

tbl_proposal has 3 important columns:

  • id_proposal
  • date
  • discount

tbl_equipments has:

  • id_equipment

  • id_proposal

  • unit_price
  • quantity

now want know how (in €) proposals year, let's say:

for each tbl_proposal.date > "2013-01-01" want use formula:

result = (tbl_equipments.unit_price * tbl_equipments.quantity) * (100 - tbl_proposal.discount) 

i can 1 sql statement?

yes can:

select e.unit_price * e.quantity) * (100 - p.discount) tbl_proposal p join      tbl_equipments e      on p.id_proposal = e.id_proposal date >= '2013-01-01' 

the basic syntax join. p , e called table aliases. make query easier read (the full table names rather bulky).

date operations differ among databases. last statement should work in databases. however, might try 1 of following well:

where year(date) = 2013 extract(year date) = 2013 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -