最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

postgresql - How can I store data associated with two keys? - Stack Overflow

programmeradmin0浏览0评论

Here is an example: Let's say I have a list of people, and for any pair of people I have some data - say the distance they live from each other.

Given a single person, I want to efficiently gather a list of all other people and their associated distances.

I could create a table like the following, but then I would have twice as many rows as I really need? E.g.

PersonA, PersonB, distance
PersonB, PersonA, distance

Are there better ways to do this? Also, aside from a database, are there data structures that solve this problem?

发布评论

评论列表(0)

  1. 暂无评论