根据状态

时间:2018-06-11 20:15:56

标签: sql join teradata

表1

vendor  SID STATUS  
1234    100 I   
567     200 NULL

表2

vendor  SID STATUS  address
1234    100 I       Stallionln
1234    100 NULL    Antlerln
567     200 NULL    prairee

结果

Table1.vendor   Table1.SID  Table2.address
1234            100         Stallionln
567             200         prairee

请提供输入以解析address,基本上Table2可以有两个状态Inull或仅NULL。如果vendor中的Table2状态有I个查询,则只显示状态为I的地址,如果没有address记录显示NULL属于this.route.parent.children

2 个答案:

答案 0 :(得分:1)

您可以加入df.loc[df.url_type_txt.str.lower().str.contains('phish'), 'url_type'] = 1 >>> df3 url_type url_type_txt 0 1 phishing/fraud 1 2 trojan 2 2 trojan 3 1 phishing 两次。一次为table2,第二次为status = 'I',然后合并结果:

status IS NULL

答案 1 :(得分:1)

您可以使用ROW_NUMBER为每个供应商只获取一个地址:

SELECT
    t1.vendor,
    t1.SID,
    t2.address
FROM table1 AS t1
LEFT JOIN 
 ( 
   SELECT * 
   FROM table2
   QUALIFY
      ROW_NUMBER() -- return only one row per vendor, prefer status 'I'
      OVER (PARTITION BY vendor
            ORDER BY status NULLS LAST) = 1
 ) AS t2 
ON t1.vendor = t2I.vendor