【发布时间】:2015-03-04 00:21:28
【问题描述】:
我使用 joomla 的 breezingform 创建 web 表单,将用户输入记录存储在数据库中,如下所示:
forms_records
id | form | name
24 19 kpi
25 19 kpi
forms_subrecords
id | element | record | description | value | type
101 406 24 month 2015-01 calendar
102 407 24 east 30% text
103 408 24 south 35% text
104 409 24 north 50% text
105 410 24 west 25% text
106 406 25 month 2015-02 calendar
107 407 25 east 45% text
108 408 25 south 35% text
109 409 25 north 15% text
110 410 25 west 5% text
我试过这样做: 1. 先获取记录id
SELECT id FROM forms_records WHERE form='19'
- 获取子记录值
SELECT s.value from forms_subrecords AS s WHERE s.record IN (SELECT id FROM forms_records WHERE form='19')
结果是10行一列,
2015-01
30%
35%
50%
25%
2015-02
45%
35%
15%
5%
但我想要的是 2 行 5 列:
2015-01 30% 35% 50% 25%
2015-02 45% 35% 15% 5%
任何人都可以帮助或提供一些提示?
【问题讨论】:
-
谢谢亚历克斯,我发现问题搞砸了,只是截图并尝试上传。
-
最后,alexander 在这里给出了答案。 https://stackoverflow.com/questions/44060426/how-to-get-two-columns-from-mysql-dynamic-table
标签: mysql