rulai
V2EX  ›  问与答

sql 语句,求一个最低价

  •  
  •   rulai · Oct 14, 2022 · 1725 views
    This topic created in 1313 days ago, the information mentioned may be changed or developed.

    table1

    id_product id_category price
    1 11 120.00
    2 11 100.00
    3 11 92.00

    table2

    id_product discount
    1 20

    产品只有 id_product 是 1 的有 20%的折扣,求打完折后的最低的价格

    2 replies    2022-10-14 20:48:47 +08:00
    andrew2558
        1
    andrew2558  
       Oct 14, 2022   ❤️ 2
    ```mssql
    select t1.Id_product,t1.Id_category,t1.price as originprice, t2.discount,
    FORMAT(t1.price*((100-ISNULL( t2.discount,0))/(100*1.0)), 'N') as newprice from table1 t1
    left join table2 t2
    on t1.Id_product= t2.Id_product
    ```

    Id_product Id_category originprice discount newprice
    1 11 120.00 20 96.00
    2 11 100.00 NULL 100.00
    3 11 92.00 NULL 92.00
    rulai
        2
    rulai  
    OP
       Oct 14, 2022
    @andrew2558 感谢,我用的 mysql ,不过我参考学习下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5715 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:20 · PVG 11:20 · LAX 20:20 · JFK 23:20
    ♥ Do have faith in what you're doing.