Yusril Ihza M Yusril Ihza M - 4 months ago 5
SQL Question

calculate profit 10% from buy price

I have this script calculates profit

Steps :


  • barangbeli = harsat / diameter

  • p1 = barangbeli * 10

  • p2 = prof / 100

  • result = barangbeli + profit;



thanks

CREATE VIEW tbkeluar as
SELECT mbarang.kdbrg, mbarang.nmbrg, mbarang.spek,if(SUM(bkeluar.qty), SUM(bkeluar.qty), 0)as qty,(tbmasuk.harsat/mbarang.diameter) as hargabeli, ((hargabeli*10)/100 )+hargabeli) as profit
LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg group by mbarang.kdbrg


i have error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as profit from mbarang
LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg gro' at line 2

Answer

The error message you received should be helpful enough to know whats wrong.

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as profit from mbarang LEFT JOIN bkeluar on mbarang.kdbrg = bkeluar.kdbrg gro' at line 2

Based from the error message, MySQL says that you have a syntax error because of this character ), with some characters appended for you to locate it: ) as profit from mbarang

As you can see from your SELECT statement, you have an extra )

SELECT  mbarang.kdbrg
    , mbarang.nmbrg
    , mbarang.spek
    ,if(SUM(bkeluar.qty), SUM(bkeluar.qty), 0)as qty
    ,(tbmasuk.harsat/mbarang.diameter) as hargabeli
    , ((hargabeli*10)/100 )+hargabeli) as profit
                                     ^ delete this extra parenthesis
Comments