如何将表格加入此结果?

时间:2013-01-15 19:00:10

标签: php mysql

我有一个表为T1,表为T2,如下所示:

T1

-------------------------------------------------------
id | price  | email
-------------------------------------------------------
1  | $1000  | jacky@domain.com
2  | $2000  | angle@domain.com
3  | $3000  | kevin@domain.com
-------------------------------------------------------

T2

-------------------------------------------------------
id | master | country | key   | value
-------------------------------------------------------
1  | 1      | US      | price | $399 
2  | 1      | US      | email | jacky/domain.us 
3  | 1      | ES      | price | $550 
4  | 1      | ES      | email | jacky@domain.es 
5  | 1      | JP      | price | $820 
6  | 1      | JP      | email | jacky@domain.jp 
7  | 2      | US      | price | $360 
8  | 2      | US      | email | angle@domain.us 
-------------------------------------------------------

如何获得此结果:

T3

----------------------------------------------------------------------------------------------------------------------------
id | price  | price_US  | price_ES  | price_JP  | email            | email_US        | email_ES        | email_JP
----------------------------------------------------------------------------------------------------------------------------
1  | $1000  | $399      | $550      | $820      | jacky@domain.com | jacky@domain.us | jacky@domain.es | jacky@domain.jp
1  | $2000  | $360      | NULL      | NULL      | angle@domain.com | angle@domain.us | NULL            | NULL
1  | $3000  | NULL      | NULL      | NULL      | NULL             | NULL            | NULL            | NULL
----------------------------------------------------------------------------------------------------------------------------

或者我可以在PHP中获得此结果吗?

T4

-------------------------------------------------------
id | price  | email             | more_info
-------------------------------------------------------
1  | $1000  | jacky@domain.com  | [array (rows...)]
2  | $2000  | angle@domain.com  | [array (rows...)]
3  | $3000  | kevin@domain.com  | [array (rows...)]
-------------------------------------------------------

有什么想法吗?

编辑1

或者我可以得到以下结果吗?

T5(国家/地区的结果)

-------------------------------------------------------
id | price  | email
-------------------------------------------------------
1  | $399   | jacky@domain.us
2  | $360   | angle@domain.us
3  | $3000  | kevin@domain.com
-------------------------------------------------------

T6(国家结果的JP)

-------------------------------------------------------
id | price   | email
-------------------------------------------------------
1  | $820    | jacky@domain.jp
2  | $2000   | angle@domain.com
3  | $3000   | kevin@domain.com
-------------------------------------------------------

1 个答案:

答案 0 :(得分:0)

我想尝试给出表之间的关系,然后再试一次。