【问题标题】:Conditional join Postgresql条件连接 Postgresql
【发布时间】:2021-04-16 13:20:45
【问题描述】:

我有一个表格,其中包含有关用户每次使用移动或网络应用程序的一些信息,即

id platform
1 web
1 mobile
2 web
2 web

我想用这个表加入另一个表,该表说明每个用户用作 phone_model 的内容

id phone_model
1 iphone
2 android

但我想有条件地加入这些,以便只有移动条目显示 phone_model 和 web 行保持为空,即仅在平台 = 'mobile' 的情况下加入该信息

id platform phone_model
1 web
1 mobile Iphone
2 web
2 web

我该怎么做?

【问题讨论】:

    标签: sql postgresql join conditional-statements


    【解决方案1】:

    你似乎想要一个left join

    select t1.*, t2.phone_model
    from table1 t1 left join
         table2 t2
         on t2.id = t1.id and t1.platform = 'mobile';
    

    【讨论】:

      猜你喜欢
      • 2011-09-04
      • 2018-12-06
      • 2021-10-27
      • 2017-06-28
      • 2016-09-03
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      相关资源
      最近更新 更多