I need to find out the final profit based on the fact that some items have discount, but the discount is set between a date interval and only then is applied on a set of items. What's wrong here?
use Companie
select sum((Facturi_Emise.Cantitate)*C.Pret+(C.Pret*B.Adaos)/100)
when (Facturi_Emise.Data_Emitere BETWEEN A.Data_Start and A.Data_stop)
select sum(((Facturi_Emise.Cantitate)*C.Pret+(C.Pret*B.Adaos)/100)-
(C.Pret*A.Discount)/100)
from Facturi_Emise
LEFT JOIN
(Select Data_Start,Data_Stop,Id_Discount,Discount from Discount)as A
on Facturi_Emise.Id_Discount=A.Id_Discount
LEFT JOIN
(select Id_Produs,Adaos from Produse)as B
on Facturi_Emise.Id_Produs=B.Id_Produs
LEFT JOIN
(Select Id_produs,Pret from Livrari)as C
on Produse.Id_Produs=C.Id_Produs