我有一个带有几张表的 MySQL 数据库。它们看起来像这样 -
食物表:
+----------+------------+--------------+
| username | date | food |
+----------+------------+--------------+
| test123 | 2012-09-16 | rice |
| test123 | 2012-09-16 | pizza |
| test123 | 2012-09-16 | french fries |
| test123 | 2012-09-16 | burger |
+----------+------------+--------------+
主表:
+----------+------------+----------------+---------------+-------------+-------------+
| username | date | water_quantity | water_chilled | smoked_what | smoke_count |
+----------+------------+----------------+---------------+-------------+-------------+
| test123 | 2012-09-16 | 1 | no | cigarettes | 20 |
+----------+------------+----------------+---------------+-------------+-------------+
当我使用查询SELECT * FROM main,food WHERE main.date=food.date;
时,我得到四行结果。我怎么可能在一行中得到结果?最终,当我将结果编码为 JSON 时,我希望它看起来像这样 -
[
{
"username":"test123",
"date":"2012-09-16",
"water_quantity":"1",
"water_chilled":"no",
"smoked_what":"cigarettes",
"smoke_count":"20",
{
"food":"rice",
"food":"pizza",
"food":"french fries",
"food":"burger",
},
}
]
或类似的东西。我是 MySQL 和数据库的新手,也是 JSON 的新手。在此先感谢您的帮助。