MySQL:如何将类似的行合并在一起?

时间:2016-08-02 23:39:06

标签: mysql sql inner-join

我在表中有大约10万行,我试图将不同事件ID的相同事件组合在一起。有两种类型的事件ID: [0-9A-F] {16} ^ [0-9] {6,7} $

我正在根据活动名称,活动日期和活动地点进行匹配。

到目前为止,我提出的最好的方法是做内部连接,但这太慢了:

SELECT  mto.eventID, mti.eventID, mto.eventName, mti.eventName, mto.venueName, mti.venueName
    FROM eventdiscovery mto
    INNER JOIN eventdiscovery mti ON
    mti.cityState = mto.cityState and mti.eventDate = mto.eventDate and mti.venueName = mto.venueName
    and mti.eventName = mto.eventName
    and ((mto.eventID REGEXP '[0-9A-F]{16}' and mti.eventID REGEXP '^[0-9]{6,7}$') or (mto.eventID REGEXP '^[0-9]{6,7}$' and mti.eventID REGEXP '[0-9A-F]{16}'))

还有其他想法吗?

1 个答案:

答案 0 :(得分:1)

您查询需要索引:event_discovery(cityState, eventDate, venueName, eventName, eventId)

正则表达式匹配确实有开销,但使用正确的索引,它可能足够快。

相关问题