内部联接表自己没有为第2列

时间:2015-12-23 06:05:11

标签: sql

    SELECT *
    FROM
    construction AS T2
    INNER JOIN  
    (
      SELECT   project,MAX(report_date)
       FROM construction 
            GROUP BY project
     ) AS R 

     ON T2.project=R.project AND T2.report_date=R.report_date

收到此错误。请帮助 没有为'R'

的第2列指定列名

3 个答案:

答案 0 :(得分:1)

您需要为SELECT * FROM construction AS T2 INNER JOIN ( SELECT project,MAX(report_date) AS report_date FROM construction GROUP BY project ) AS R ON T2.project = R.project AND T2.report_date = R.report_date; 添加别名:

SQL Server

SELECT * FROM construction AS T2 INNER JOIN ( SELECT project,MAX(report_date) FROM construction GROUP BY project ) AS R(project, report_date) ON T2.project = R.project AND T2.report_date = R.report_date; 中,您可以使用语法:

<body>

<input type="checkbox" id="sidebartoggler" name=" " value="" />

<div class="page-wrap">

    <label for="sidebartoggler" class="toggle">☰</label>

    <div class="side-content">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
    </div>

  <div class="centercontent"></div>

    <div class="sidebar">
        <ul>
            <li>Home</li>
            <li>Projects</li>
            <li>Clients</li>
            <li>Blog</li>
            <li>Contact</li>
        </ul>
    </div>
</div>

</body>

答案 1 :(得分:0)

您应该使用别名MAX(report_date)来指定report_date 因为您的表格R有两列project,MAX(report_date)

答案 2 :(得分:0)

您收到此错误是因为您没有为内部查询指定列名

您必须将查询编写为

SELECT * 从建筑 INNER JOIN
(   SELECT项目,MAX(report_date)“Max_ReportDate”   从建筑   GROUP BY项目 )Max_construction   ON construction.project = Max_construction .project  AND construction.report_date = Max_construction .Max_ReportDate