用于 VS 代码的 MySQL Shell GUI / MySQL Shell / 第 9 章打字稿 /
9.2 数据库笔记本:使用 SELECT 语句检索数据
全面上市前:2022-11-17
runSql(
"SELECT Name as label, District as district, Population as value FROM world.city WHERE Name = 'Kabul' ",
(res: ResultSetRows) => {
print(res);
}
);
输出是:
[ { “标签”:“喀布尔”, “区”:“喀布尔”, “价值”:1780000 } ]
const graphData = [];
runSqlIterative(
"SELECT rating as label , count(rating) as value FROM sakila.film " +
"GROUP BY rating",
(res: IResultSetData) => {
if (res.rows) {
res.rows.forEach((row, index) => {
graphData.push({
label: row[1] as string,
value: 25,
});
});
}
if (res.requestState.type === "OK") {
print(res);
}
}
);
输出是:
{ “请求状态”:{ “类型”:“确定”, "msg": "包含 5 行传输的完整结果集。" }, “requestId”:“6ee28aa2-2727-42d9-2bd9-d60f8d4abb64”, “行”:[ [ "PG", 194 ], [ “G”, 178 ], [ "NC-17", 210 ], [ "PG-13", 223 ], [ "R", 195 ] ], “列”: [ { "名称": "标签", “类型”:“枚举”, “长度”:20 }, { "名称": "值", “类型”:“整数”, “长度”:21 } ], “完成”:是的, “总行数”:5, “执行时间”:0.0009739398956298828 }