Subject Re: Substraction of 2 selections
Author Svein Erling
--- In firebird-support@yahoogroups.com, rpoulin wrote:
> I want to substract those two following selections from my KIT
> table and put the result in a new field called DELTAPRICE. Do i need
> to create a function to take care of the script ?
>
> select DETAIL_KIT.PRIX_MARGE_DETAIL, DETAIL_KIT.PRINCIPAL from
> DETAIL_KIT where PRINCIPAL ='O' order by NO_ORDRE
>
> [ minus ]
>
> select DETAIL_KIT.PRIX_MARGE_DETAIL, DETAIL_KIT.PRINCIPAL from
> DETAIL_KIT where PRINCIPAL ='N' order by NO_ORDRE
>
> THANK ..... a lot ...
> Richard P

Simple, Richard, just do

select DK1.PRIX_MARGE_DETAIL, DK1.PRINCIPAL from
DETAIL_KIT DK1
where DK1.PRINCIPAL ='O'
and not exists (select * from DETAIL_KIT DK2
where DK2.PRIX_MARGE_DETAIL = DK1.PRIX_MARGE_DETAIL
and DK2.PRINCIPAL ='N')
order by NO_ORDRE

HTH,
Set