SHARE
TWEET

sqlquery

a guest Apr 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.   GROUP_CONCAT(DISTINCT
  3.     CONCAT(
  4.       'MAX(IF(sp.name = ''',
  5.       name,
  6.       ''', sp.value, NULL)) AS ',
  7.       name
  8.     )
  9.   ) INTO @sql
  10. FROM SampleParameters;
  11.  
  12. SET @sql = CONCAT('SELECT s.id
  13.                     , s.sampleName
  14.                     ,  ', @sql, '
  15.                    FROM Samples s
  16.                    LEFT JOIN SampleParameters AS sp
  17.                     ON s.id = sp.sampleID
  18.                    GROUP BY s.id');
  19.  
  20. PREPARE stmt FROM @sql;
  21. EXECUTE stmt;
  22. DEALLOCATE PREPARE stmt;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top