在联合表(SQLite)中选择匹配多个标准的外键匹配多个标准
序言:这一切都在小提琴中 /f/pmlfrz59ael7b2jusmtt9x/1
我有一个包含项目的表(item#100,item#101 ...
),每个表都有各种属性(code> colod> color,type,type,stype,size,size size
)。因为一组属性不一致(例如,在下表中,item#100
是帽子,通常不具有尺寸),所以我创建了一张属性类型的项目地图和每个项目的属性值。
项目 | 类型 | 值 |
---|---|---|
项目#100 | 颜色 | 红色 |
项目#100 | 类型 | 帽子 |
项目#101 | 颜色 | 蓝色 |
项目#101 | 大小 | S |
项目#101 | 类型 | T恤 |
SNIP ,
但是我现在正在努力通过任意集来检索项目在多个标准中 - 例如,我不确定如何选择具有:
属性类型size
带有属性值s
s
和
的所有项目属性类型颜色
,属性值blue
(示例,查询将返回iteg <代码>项目#101
和item#103 < /code>)
我通过选择所有单个标准成功地检索了行,然后Intersect
一起(例如,选择“ S”的所有内容与选择“ blue”的所有内容相交)。这似乎不是一个很好的解决方案,因为要查询会更改的完整标准(有时只能通过一个属性,有时会通过多个属性),
我在所有这些方面都相对较新,但是通过SQLite的文档阅读关于正确社区中的索引...
Preface: this is all in a fiddle here https://www.db-fiddle.com/f/pMLFrz59aeL7B2jUsmTt9X/1
I have a table that contains items (item #100, item #101...
) that each have various attributes (color, type, size
). Because the set of attributes are not consistent (e.g. in the table below, item #100
is a hat, which don't typically have a size), I created a map of the items to the attribute type and attribute value for each of the items.
Item | Type | Value |
---|---|---|
Item #100 | Color | Red |
Item #100 | Type | Hat |
Item #101 | Color | Blue |
Item #101 | Size | S |
Item #101 | Type | T-Shirt |
Snip
However I am now struggling to retrieve items by an arbitrary set of multiple criteria — for example, I am unsure of how to select all items that have:
Attribute type Size
with attribute value s
AND
Attribute type Color
, attribute value Blue
(which, for the example, the query would return Item #101
and Item #103
)
I successfully retrieved the rows with selecting all of the individual criteria and then Intersect
ing them together (e.g. select everything of size "s" intersected with select everything of color "blue"). That didn't seem like a good solution as the full set of criteria to query by will change (sometimes it will only by one attribute, sometimes it will be by multiple)
I am relatively new at all of this, but reading through sqlite's documentation about indices felt in the right neighborhood...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论