这是我的表描述:
CREATE TABLE my_table ( id
int, name
varchar(9), value
varchar(13)) ;
INSERT INTO my_table ( id
, name
, value
) VALUES (0, 'timezone', 'Europe/London'), (0, 'language', 'en'), (0, 'country', '45'), (0, ' something', 'x'), (1, 'timezone', 'Europe/Paris'), (1, 'language', 'fr'), (1, 'country', '46') ;
id name value
0 timezone Europe/London
0 language en
0 country 45
0 something x
1 timezone Europe/Paris
1 language fr
1 country 46
我的结果应该看起来
ID TIMEZONE LANGUAGE COUNTRY SOMETHING
0 Europe/London en 45 x
1 Europe/Paris fr 46 (null)
如何在 Zend Framework 中使用 Zend_Db_Table 或 Zend_Db_Select 执行此查询?太感谢了!
[添加评论中的编辑查询]
SELECT CONCAT( 'SELECT table.id', GROUP_CONCAT(CONCAT(' , t_', REPLACE(name, '', ''), '`.value AS `', REPLACE(name, '`', ''), '' ) SEPARATOR ''), '
FROM table` ',
GROUP_CONCAT(CONCAT(' LEFT JOIN table AS t_', REPLACE(name, '', ''), '` ON `table`.id = `t_', REPLACE(name, '`', ''), '.id AND t_', REPLACE(name, '', '``'), '.name = ',
QUOTE(name) ) SEPARATOR ''), '
GROUP BY table.id' )
INTO @qry FROM (SELECT DISTINCT name FROM table) t;
PREPARE stmt FROM @qry;
EXECUTE stmt;