要在单个单元格中添加一组元素,请使用JSON的概念。让我们首先创建一个表-
mysql> create table DemoTable1828 ( EmployeeId int, EmployeeRecords JSON );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1828 values(1,'[{"EmployeeName":"Chris","EmployeeAge":29},{"EmployeeName":"David","EmployeeAge":27}]'); mysql> insert into DemoTable1828 values(2,'[{"EmployeeName":"John","EmployeeAge":36},{"EmployeeName":"Mike","EmployeeAge":32}]');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1828;
这将产生以下输出-
+------------+----------------------------------------------------------------------------------------------+ | EmployeeId | EmployeeRecords | +------------+----------------------------------------------------------------------------------------------+ | 1 | [{"EmployeeAge": 29, "EmployeeName": "Chris"}, {"EmployeeAge": 27, "EmployeeName": "David"}] | | 2 | [{"EmployeeAge": 36, "EmployeeName": "John"}, {"EmployeeAge": 32, "EmployeeName": "Mike"}] | +------------+----------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)