Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql——如何检索NVP值并将其分组?_Mysql_Nvp - Fatal编程技术网

Mysql——如何检索NVP值并将其分组?

Mysql——如何检索NVP值并将其分组?,mysql,nvp,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(Sa

假设我们有这个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)
)

MySQL没有数组,因此很难确定您期望的确切结果集。在任何情况下,DB设计都无法将作者与项目匹配:这样的信息根本不存储在任何地方

我想你有理由避免这样做:

author            item
======            ======
Sabriel Armstrong bell
Peter Abhorsen    book

:-?

我不能将其设置为列的原因是字段名称和值是任意的,可以更改。