【问题标题】:SQL: Select rows if it fuzzy matches with corresponding columnSQL:如果与相应列模糊匹配,则选择行
【发布时间】:2019-10-10 20:01:38
【问题描述】:

我有一个有 2 列的数据框

**Job**    **Station**
Service      ServiceA
Wash         ServiceA
Service      WashA
Service      ServiceA
Wash         WashA
Wash         WashB 
Wash         Invoice
Wash         Entry
Service      Invoice
Service      Entry

Job 取值为 Service 或 Wash,而 Station 取值为 ServiceA、ServiceB、WashA、WAshB。有与作业“服务”对应的条目为“WashA”,这是不正确的,因为服务应仅对应于服务 A 或服务 B。条目和发票应保留在每项工作中。我想选择仅正确映射的行。

我该怎么做?

【问题讨论】:

    标签: sql select presto case-when


    【解决方案1】:

    我怀疑你想要:

    select t.*
    from t
    where station like concat(job, '%')
    

    这会检查station 中的前导字符是否与job 匹配。

    【讨论】:

    • 你是对的,但我只是稍微编辑了这个问题。你也能帮忙吗?
    • select t.* from t where station in (concat(job, '%'), 'Entry', 'Invoice') 。这行不通。它只选择条目和发票
    猜你喜欢
    • 2014-10-15
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 2016-08-28
    • 1970-01-01
    相关资源
    最近更新 更多