Mysql -- 如何检索 NVP 值并对它们进行分组?
假设我们有这个 MySQL 表
name value
author Sabriel Armstrong
author Peter Abhorsen
author Garth Stein
item bell
item book
item sword
item wand
给定这些数据库条目,有没有办法检索这些值并以下面的格式获取它?或者我的数据库建模错误?
array(
[author] => array(Sabriel Armstrong,Peter Abhorsen, Garth Stein),
[item] => array(bell,book,sword, wand)
)
Lets say we have this MySQL table
name value
author Sabriel Armstrong
author Peter Abhorsen
author Garth Stein
item bell
item book
item sword
item wand
Given these database entries, is there a way to retrieve this values as to get it in the format below? Or is my database modeling wrong?
array(
[author] => array(Sabriel Armstrong,Peter Abhorsen, Garth Stein),
[item] => array(bell,book,sword, wand)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL 没有数组,因此很难确定您期望的确切结果集。无论如何,您的数据库设计无法提供将作者与项目相匹配的方法:此类信息根本不存储在任何地方。
我想你会有理由避免这种情况::
-?
MySQL does not have arrays so it's hard to figure out what exact result set you are expecting. In any case, your DB design provides no way to match an author with an item: such information is simply not stored anywhere.
I suppose you'll have a reason to avoid this:
:-?