V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
rulai
V2EX  ›  问与答

sql 语句,求一个最低价

  •  
  •   rulai · 2022-10-14 20:20:23 +08:00 · 888 次点击
    这是一个创建于 565 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2022-10-14 20:48:47 +08:00
    andrew2558
        1
    andrew2558  
       2022-10-14 20:41:03 +08:00   ❤️ 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
       2022-10-14 20:48:47 +08:00
    @andrew2558 感谢,我用的 mysql ,不过我参考学习下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2228 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:30 · PVG 17:30 · LAX 02:30 · JFK 05:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.