通过此查询创建视图

时间:2019-02-05 16:28:34

标签: php mysql

是否可以通过此查询创建视图?该查询用于将行转换为列。还是无法显示,如何在php上显示值?

 SET @sql = NULL;
    SELECT
      GROUP_CONCAT(DISTINCT
        CONCAT(
          'max(case when subjectID = ''',
          subjectID,
          ''' then FirstGrading end) AS `',
          subjectID, '`'
        )
      ) INTO @sql
    FROM  view_all_grades_final_edit_last;

    SET @sql = CONCAT('SELECT studentID,lname, ', @sql, ' 
                      FROM view_all_grades_final_edit_last 
                      GROUP BY lname');

    PREPARE stmt FROM @sql;
    EXECUTE stmt;

输出:

    studentID | lname | Computer 101 | History 101 | Java 101 | PE 101 | Science 101
     14-2387      Akbar  0.00           0.00          0.00       0.00     79.93
......

0 个答案:

没有答案