带参数的函数查询

时间:2017-01-21 16:02:31

标签: mysql sql function

Tax1 = SELECT a.harga_triumph * b.nilai_desimal 
from tbl_detail mc a 
JOIN penyesuaian b on a.id=b.id

Tax2 = Tax1 * (c.nilai_desimal from bea_masuk where kode='BM')

Tax3 = c.nilai_desimal from bea_masuk where kode='PPNImpor' * (Tax1 + Tax2)

Tax4 = c.nilai_desimal from bea_masuk where kode='PPNBM' * (Tax3)

Tax5 = c.nilai_desimal from bea_masuk where kode='PRH' * (Tax3)

AllTax = Tax2 + Tax3 + Tax4 + Tax5

Total Price = a.harga_triumph + All Tax

where a.id=@parameter

我坚持使用函数进行此查询。

英文翻译:

harga_triumph = unit price
nilai_desimal = decimal (0.1,0.2)
penyesuaian = adjustment

SQL小提琴:http://sqlfiddle.com/#!9/31244/1

1 个答案:

答案 0 :(得分:0)

我已经通过不使用该函数解决了这个问题,我只是在查询上使用了一个简单的集合,就像这样

set @dectax1 = (select round(nilai_desimal,3) from bea_masuk where id=1;
set @tax1 = (select round(harga_triumph * @dectax1)); from tbl_detail_mc where id=1);

如果要显示结果,请使用@ tax1中的查询。 等等...