The web business needs to be sorted by actual amount of money, with three fields: price (commodity prices), pay (actual paid price), Num (quantity purchased). If the product has a discount is based on pay prices, that is, pay>0, if there is no discount is the price of the deal, pay=0. So the actual price we want is if pay>0 is pay*num, otherwise it is price*num. This is to use three mesh operation pay >0?pay:price.
So does MySQL have three-mesh operators?
When you can use case, this MySQL should support: Select A,case when B is null then ' xxxx ' else B-B from table_xxx where. and this.
SQL is also supported in the three-mesh operation, the syntax is:
case when condition THEN if conforming ELSE if not conforming to end
So the SQL statements in our business are:
The Select Case is pay>0 THEN pay*num ELSE price*num end as ' amount ' from table_name to amount;