rulai
V2EX  ›  问与答

sql 语句,求一个最低价

  •  
  •   rulai · Oct 14, 2022 · 2150 views
    This topic created in 1480 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
    andrew2558
    Oct 14, 2022❤️2
    1
    ```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
    rulai
    OP
    Oct 14, 2022
    2
    @andrew2558 感谢,我用的 mysql ,不过我参考学习下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4986 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:56 · PVG 14:56 · LAX 22:56 · JFK 01:56
    ♥ Do have faith in what you're doing.