【发布时间】:2014-07-31 05:20:06
【问题描述】:
我有一个应用程序,用户可以在其中拍摄图像并自行标记它们。这是数据库结构的样子:
为了解决这个问题,让我们来看看三个主要的表:
用户,图像,用户图像
user table
id, user_name, age
1, test1, 23
2, test2, 34
image table
id, users_in_image, datetime
1, test1,test2, 03/01/2000
2, test1, 03/01/2003
user_image table
id, user_id, image_id
1, 1, 1
2, 1, 2
每次用户拍摄图像时,它都会在 image、user 和 user_image 中创建一个记录,给定一个用户,我想查看该用户与之拍摄图像的所有用户以及这些 image_id 是什么。
这是我的解决方案
select * from user_image where image_id
in (select image_id from user_image where user_id = '1') and user_id != '1';
我担心这不是一个好的解决方案。我想从专家那里得到一些想法。
【问题讨论】:
-
图片表中users_in_image字段是一个数组吗?
-
不,不幸的是,它的逗号分隔文本数据库不是这样设计的。
-
找到设计它的人并用线索蝙蝠敲打他们。轻轻地。
-
您的问题是什么?你试过什么?显示示例结果。等
-
您的问题可能不应该是“最有效”的标题,因为您甚至根本没有解决方案。
标签: sql postgresql