如何从2个相关表中选择多个列

时间:2015-08-01 13:12:10

标签: mysql select

我想从我的2个表格中选择多个列:

表货币

    select * from Currency order by timestamp desc limit 30;

+----------+----------+--------+--------+---------------------+
|  platID  | currency | buy    | sell   | timestamp           |
+----------+----------+--------+--------+---------------------+
|        2 | EUR      | 4.1281 | 4.1561 | 2015-08-01 13:47:01 |
|        1 | USD      | 3.7589 | 3.7889 | 2015-08-01 13:47:01 |
|        2 | USD      | 3.7563 | 3.7843 | 2015-08-01 13:47:01 |
|        2 | GBP      | 5.8732 | 5.9122 | 2015-08-01 13:47:01 |
|        1 | EUR      | 4.1265 | 4.1565 | 2015-08-01 13:47:01 |
|        1 | GBP      | 5.8734 | 5.9134 | 2015-08-01 13:47:01 |
|        2 | CHF      | 3.8904 | 3.9249 | 2015-08-01 13:47:01 |
|        1 | CHF      | 3.8928 | 3.9328 | 2015-08-01 13:47:01 |
|        1 | USD      | 3.7589 | 3.7889 | 2015-08-01 13:46:02 |
|        1 | GBP      | 5.8734 | 5.9134 | 2015-08-01 13:46:02 |
|        1 | EUR      | 4.1265 | 4.1565 | 2015-08-01 13:46:02 |
|        1 | CHF      | 3.8928 | 3.9328 | 2015-08-01 13:46:02 |
|        2 | USD      | 3.7563 | 3.7843 | 2015-08-01 13:46:01 |
|        2 | EUR      | 4.1281 | 4.1561 | 2015-08-01 13:46:01 |
|        2 | CHF      | 3.8904 | 3.9249 | 2015-08-01 13:46:01 |
|        2 | GBP      | 5.8732 | 5.9122 | 2015-08-01 13:46:01 |
+----------+----------+--------+--------+---------------------+

表格平台

select * from Platforms

+----------+----------------------+
|  platID  | domain               |
+----------+----------------------+
|        0 | domain1              |
|        1 | domain2          |
|        2 | domain3              |
|        3 | domain4              |
|        4 | domain5              |
|        5 | domain6              |
+----------+----------------------+

我希望从表平台获取所请求货币或所有货币的每个域的以下输出

+-----------+-----------------+------------------+-----------------+------------------+
| timestamp | domain1 USD buy | domain1 USD sell | domain2 USD buy | domain2 USD sell | 
+-----------+-----------------+------------------+-----------------+------------------+
|   13:44   |     3.7589      |      3.7889      |     3.7589      |      3.7889      |
+-----------+-----------------+------------------+-----------------+------------------+

0 个答案:

没有答案