开发者社区 问答 正文

关于Mysql的一个查询问题

现在遇到这样的一个问题,有两个表(表1、表2),要生成表3,相应的Mysql的SQL语句应该是怎样的?
表1
ID    PropertyID1    PropertyID2    PropertyID3    Content
1    1    2    3    aaaa
2    2    3    5    bbbb
3    1    3    4    cccc
表2
PropertyID    Property_Name
1    苹果
2    李子
3    香蕉
4    菠萝
5    橙子
表3
ID    Property_Name1    Property_Name2    Property_Name3    Content
1    苹果    李子    香蕉    aaaa
2    李子    香蕉    橙子    bbbb
3    苹果    香蕉    菠萝    cccc

展开
收起
平阳 2014-08-31 17:16:02 9373 分享 版权
1 条回答
写回答
取消 提交回答
  • Re关于Mysql的一个查询问题
    试试这样是否可以
    SELECT
      ID,
      (SELECT
        Property_Name
      FROM
        table2 t2
      WHERE t1.PropertyID1 = t2.PropertyID) AS Property_Name1,
      (SELECT
        Property_Name
      FROM
        table2
      WHERE t1.PropertyID1 = t2.PropertyID) AS Property_Name2,
      (SELECT
        Property_Name
      FROM
        table2
      WHERE t1.PropertyID1 = t2.PropertyID) AS Property_Name3,
      Content
    FROM
      table1 t1




    2014-08-31 17:43:51
    赞同 展开评论