MySQL:如何将此数据透视表分成一行?

时间:2015-03-10 14:25:22

标签: mysql

我正在尝试使用table_name周围的以下查询在mySQL中执行一个数据透视图,将事件和设置重新格式化为列:

select 
id, 
submitted, 
case when table_name = 'events' then pulled end as events,
case when table_name = 'settings' then pulled end as settings

from ods.ods_table where name = "time_pulled" and table_name in ("events","settings")

group by id, pulled;

但我得到了这些结果。我如何对它进行分组,以便id 26只获得一行,而id 31也获得一行,例如。在这种情况下,group by似乎没有帮助我。

+----+---------------------+---------------------+---------------------+
| id |      submitted      |      settings       |       events        |
+----+---------------------+---------------------+---------------------+
| 20 | 2015-03-10 09:41:17 |                     | 2015-03-10 09:41:17 |
| 26 | 2015-03-10 09:39:33 | 2015-03-10 09:39:33 |                     |
| 26 | 2015-03-10 09:39:34 |                     | 2015-03-10 09:39:34 |
| 30 | 2014-03-28 16:56:50 | 2014-03-28 16:56:50 |                     |
| 31 | 2015-03-10 09:42:31 | 2015-03-10 09:42:31 |                     |
| 31 | 2015-03-10 09:42:32 |                     | 2015-03-10 09:42:32 |
+----+---------------------+---------------------+---------------------+

如何通过ID将它们分组到一行?谢谢!

0 个答案:

没有答案