每位客户的日期

时间:2016-04-23 06:26:33

标签: mysql

客户表:

|   id   |   name   |
---------------------
|   1    |   John   |
|   2    |   Mike   |

日历表:

|  date      |
--------------------
| 2015-01-01 |
| 2015-01-02 |
| 2015-01-03 |

问题:如何获得此结果?

所需结果:

|  name   |  date      |
------------------------
|  John   | 2015-01-01 |
|  John   | 2015-01-02 |
|  John   | 2015-01-03 |
|  Mike   | 2015-01-01 |
|  Mike   | 2015-01-02 |
|  Mike   | 2015-01-03 |

2 个答案:

答案 0 :(得分:2)

使用CROSS JOIN

SELECT 
    Customers.name, 
    Calendar.date
FROM Customers 
CROSS JOIN Calendar 

答案 1 :(得分:1)

使用以下查询获得所需结果

select t1.name as name,t2.date as date 
from Coustomers t1 
join Calendar t2 on 1=1