Good day,

I just want to asked regarding SQL.

let say i have a table for discount.using SQL query.

here my table name A

            Item              Price
           A              100.00
           B              200.00
           C              300.00

Assume that there's 20% discount if the price is greater than 200.00 Discount should apply

  1. How could i create a query for that?
  2. Using C# or SQL statement how could i insert the record?


The easiest way would be by case:

select item, price, case when price > 200 then 20% else 0 end as discount
from table_name

another way to do it is:

select item, price, 0.2 as discount from table_name where price > 200 
select item, price, 0 from table_name where price <= 200

if you are inserting, you can either go with case, insert without the discount and in the same transaction update the records you've inserted with the discount or handle it when you are building the data for the insert.