Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Set rows value as column name using MySql version 8.0.17

$
0
0

Hi,

I populate a table of a database MySql version 8.0.17, with an external file in csv format.

This is the table filled with data from the external csv file

SELECT*FROM `t_contents_s3sv_1_2021` orderby sID asc;+-----------------------+--------+-----+| contents              | sUnity | sID |+-----------------------+--------+-----+|Set n.1| Q400   |4||- Par 1.1| Q400   |6||<b>bold text</b>| Q400   |7||- Par 1.2| Q400   |9|| normal text           | Q400   |10||Set n.2| Q400   |12||- Par 2.1| Q400   |14||<i>italic text</i>| Q400   |15||- Par 2.2| Q400   |16||<u>underline text</u>| Q400   |17||- Par 2.3| Q400   |71||Set n.1| Q410   |72||- Par 1.1| Q410   |73||<b>bold text</b>| Q410   |74||- Par 1.2| Q410   |75|| normal text           | Q410   |76||Set n.2| Q410   |77||- Par 2.1| Q410   |78||<i>italic text</i>| Q410   |79||- Par 2.2| Q410   |80||<u>underline text</u>| Q410   |81||- Par 2.3| Q410   |82|+-----------------------+--------+-----+22rowsinset (0.03 sec)

Now I need this return I mean set rows values as column name

+-----------------------+-----------------------+| Q400                  | Q410                  |+-----------------------+-----------------------+|Set n.1|Set n.1||- Par 1.1|- Par 1.1||<b>bold text</b>|<b>bold text</b>||- Par 1.2|- Par 1.2|| normal text           | normal text           ||Set n.2|Set n.2||- Par 2.1|- Par 2.1||<i>italic text</i>|<i>italic text</i>||- Par 2.2|- Par 2.2||<u>underline text</u>|<u>underline text</u>||- Par 2.3|- Par 2.3||Set n.1|Set n.1||- Par 1.1|- Par 1.1||<b>bold text</b>|<b>bold text</b>||- Par 1.2|- Par 1.2|| normal text           | normal text           ||Set n.2|Set n.2||- Par 2.1|- Par 2.1||<i>italic text</i>|<i>italic text</i>||- Par 2.2|- Par 2.2||<u>underline text</u>|<u>underline text</u>||- Par 2.3|- Par 2.3|+-----------------------+-----------------------+

I tried to search posts, without any result either, maybe I didn't use the right words.

Structure and data of table below

-- ------------------------------ Table structure for t_contents_s3sv_1_2021-- ----------------------------DROPTABLE IF EXISTS `t_contents_s3sv_1_2021`;CREATETABLE `t_contents_s3sv_1_2021`  (
  `contents` varchar(255) DEFAULTNULL,
  `sUnity` varchar(50) DEFAULTNULL,
  `sID` int(11) NOTNULL AUTO_INCREMENT,PRIMARY KEY (`sID`) USING BTREE,UNIQUE INDEX `contents`(`contents`, `sUnity`) USING BTREE
) ENGINE = InnoDB;-- ------------------------------ Records of t_contents_s3sv_1_2021-- ----------------------------INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 1.1', 'Q400', 6);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 1.1', 'Q410', 73);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 1.2', 'Q400', 9);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 1.2', 'Q410', 75);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.1', 'Q400', 14);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.1', 'Q410', 78);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.2', 'Q400', 16);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.2', 'Q410', 80);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.3', 'Q400', 71);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('- Par 2.3', 'Q410', 82);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<b>bold text</b>', 'Q400', 7);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<b>bold text</b>', 'Q410', 74);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<i>italic text</i>', 'Q400', 15);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<i>italic text</i>', 'Q410', 79);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<u>underline text</u>', 'Q400', 17);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('<u>underline text</u>', 'Q410', 81);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('normal text', 'Q400', 10);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('normal text', 'Q410', 76);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('Set n.1', 'Q400', 4);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('Set n.1', 'Q410', 72);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('Set n.2', 'Q400', 12);INSERTINTO `t_contents_s3sv_1_2021` VALUES ('Set n.2', 'Q410', 77);

Viewing all articles
Browse latest Browse all 1350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>