在以下情况下,<比较与!=有何不同?

时间:2020-07-08 18:38:22

标签: mysql sql python-dedupe

我正在尝试了解https://dedupeio.github.io/dedupe-examples/docs/mysql_example.html上的该示例。在以下情况下,<比较与!=有何不同?

 read_cur.execute("""
           select a.donor_id,
                  json_object('city', a.city,
                              'name', a.name,
                              'zip', a.zip,
                              'state', a.state,
                              'address', a.address),
                  b.donor_id,
                  json_object('city', b.city,
                              'name', b.name,
                              'zip', b.zip,
                              'state', b.state,
                              'address', b.address)
           from (select DISTINCT l.donor_id as east, r.donor_id as west
                 from blocking_map as l
                 INNER JOIN blocking_map as r
                 using (block_key)
                 **where l.donor_id < r.donor_id) ids**
           INNER JOIN processed_donors a on ids.east=a.donor_id
           INNER JOIN processed_donors b on ids.west=b.donor_id
           """)

VS

    read_cur.execute("""
           select a.donor_id,
                  json_object('city', a.city,
                              'name', a.name,
                              'zip', a.zip,
                              'state', a.state,
                              'address', a.address),
                  b.donor_id,
                  json_object('city', b.city,
                              'name', b.name,
                              'zip', b.zip,
                              'state', b.state,
                              'address', b.address)
           from (select DISTINCT l.donor_id as east, r.donor_id as west
                 from blocking_map as l
                 INNER JOIN blocking_map as r
                 using (block_key)
                 **where l.donor_id != r.donor_id) ids**
           INNER JOIN processed_donors a on ids.east=a.donor_id
           INNER JOIN processed_donors b on ids.west=b.donor_id
           """)

1 个答案:

答案 0 :(得分:1)

使用<时,可以确保每对仅包含一次。

l.donor_id  r.donor_id
    1           2
    3           4

如果您使用!=,则每对将包含两次。

l.donor_id  r.donor_id
    1           2
    2           1
    3           4
    4           3