将行作为列的动态交叉制表符

时间:2014-03-05 13:27:54

标签: mysql crosstab

我无法制作有问题的交叉表,请帮帮我

SET @sql = NULL;
    SELECT  group_concat(CONCAT(', SUM(IF(TX_FIRST_NAME = "',TX_FIRST_NAME,'", 1,0)) AS `',TX_FIRST_NAME,'`'))
    INTO @sql
    FROM cmn_physician ;
    SET @sql = CONCAT('
    SELECT p.KYS_ID, b.DT_DATE, ', @sql, '
      from cmn_physician p left join cmn_physician_x_provider pro 
    on p.KYS_ID=pro.FKYS_PHYSICIAN_ID   left join cmn_bill b
    on b.FKYS_PROVIDER_ID=pro.FKYS_PROVIDER_ID 
    group by p.TX_FIRST_NAME');

    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;

0 个答案:

没有答案