表SQL

version 1.3.0 (3.74 KB) by Tommaso Belluzzo
用于在MATLAB表上执行SQL CRUD操作的脚本。

167下载

Updated2020年7月17日

查看许可证

# 介绍 #

Basically, this script is a SQL wrapper around Matlab tables. It is especially useful for those who are new to Matlab and have the habit of "thinking in SQL", or for those who need to accomplish complex data manipulation tasks and struggle to achieve them with the built-in table manipulation functions.

#方法和用法#

“ table_sql”函数接受一个单个输入参数,该参数必须是有效的SQL CRUD语句(删除,插入,选择或更新),其中表名是在主工作区中定义的普通MATLAB表。

解析查询后,脚本将设置SQLITE数据库的内存实例,导入表,执行指定的SQL语句,将工作空间表与数据库同步并返回结果。后者的内容取决于执行的操作:
>对于选择语句,一个表示数据库返回的结果集的m-n表;
>对于删除,插入和更新语句,一个代表受影响行数的整数。

# 例子 #

1)设置:
load('patients');
ids = (1:numel(LastName)).';
t1 = table(ids,lastName,性别,'variablenames',{'id''''''''''''''gender'});
t2 =表(ID,年龄,身高,体重,'variablenames',{'id''''''''高度''strige'});

2)选择(有和没有分配):
t3 = table_sql('select a.id,a.lastname,B。从t1 a内连接t2 b on b.id = a.id');
table_sql('选择年龄,avg(高度)从t1 a内的联接t2 b on b.id = a.id a.id组按年龄按年龄按年龄划分”);

3)修改:
ar = table_sql('DELETE FROM t1 WHERE Gender = "Male"'); t1
ar = table_sql('UPDATE t2 SET Age = Age + 1 WHERE Age >= 40'); t2

#笔记#

>The script requires a SQLite JDBC driver, which can be downloaded from the following link:https://bitbucket.org/xerial/sqlite-jdbc/downloads/。必须将“ .jar”文件放在脚本文件夹中。
>被查询的表的列类型归一化如下:分类和字符串变为字符阵列,逻辑变为8位整数(字节),整数变成双倍。

引用为

Tommaso Belluzzo(2022)。表SQL(//www.tianjin-qmedu.com/matlabcentral/fileexchange/68771-Table-sql),Matlab中央文件交换。检索

MATLABRelease Compatibility
Created with R2018a
与R2015B至R2018B兼容
平台兼容性
Windows 苹果系统 Linux

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!