需要帮助来构建一个SQL查询

时间:2013-04-07 08:16:52

标签: mysql sql

我有一个包含以下架构的表

示例表

email        |  name  |  address 
1@gmail.com  |  A     |  CA

我想要具有五个不同静态电子邮件地址的同一组记录

预期输出

email              |   name   |   address
static1@gmail.com  |   A      |   CA
static2@gmail.com  |   A      |   CA
static3@gmail.com  |   A      |   CA
static4@gmail.com  |   A      |   CA
static5@gmail.com  |   A      |   CA

这可能吗?

1 个答案:

答案 0 :(得分:1)

尝试

SELECT CONCAT('static', @n := @n + 1, '@', SUBSTRING_INDEX(email, '@', -1)) email,
       `name`,
       address
  FROM table1 CROSS JOIN  
       INFORMATION_SCHEMA.COLUMNS JOIN
       (SELECT @n := 0) n
 LIMIT 5

输出:

|             EMAIL | NAME | ADDRESS |
--------------------------------------
| static1@gmail.com |    A |      CA |
| static2@gmail.com |    A |      CA |
| static3@gmail.com |    A |      CA |
| static4@gmail.com |    A |      CA |
| static5@gmail.com |    A |      CA |

<强> SQLFiddle