mySQL - update multiple columns with a select returning multiple rows

前端 未结 4 1569
臣服心动
臣服心动 2021-01-04 03:02

I have a table of postcodes and I want to update each postcode with its 3 nearest neighbours. Ie to fill in the blanks in this table:

postcode  nearestPostco         


        
4条回答
  •  自闭症患者
    2021-01-04 03:39

    Anytime I see a table with columns that have 1-up counters after their names, I get concerned.

    In general, it is a Bad Idea (TM) to store data that can be calculated from data that is already stored. What happens if your application all of a sudden needs the 4 closest postal codes? What if the postal code boundaries change?

    Assuming the distance calculation isn't very complex, you'll be better off in the long run not explicitly storing this data.

提交回复
热议问题