alasql - 使用 alasql 时在 SQL 中使用变量时遇到问题
问题描述
这可能是一个初学者的问题,但我不知道如何在 SQL 查询中使用变量。
const CCqry = req.params.CC; // It contains a string
var values =Object.values(DATA.laureates);
const result = alasql("SELECT * FROM ? WHERE bornCountryCode = \"%CCqry\" ", [values]);
以上对我不起作用,不知道我做错了什么。
但是下面的一个有效,
const CCqry = req.params.CC; // It contains a string
var values =Object.values(DATA.laureates);
const result = alasql("SELECT * FROM ? WHERE bornCountryCode = \"US\" ", [values]);
我指的 JSON 是
{
"laureates": [
{
"id": "1",
"firstname": "Wilhelm Conrad",
"surname": "Röntgen",
"born": "1845-03-27",
"died": "1923-02-10",
"bornCountry": "Prussia (now Germany)",
"bornCountryCode": "DE",
"bornCity": "Lennep (now Remscheid)",
"diedCountry": "Germany",
"diedCountryCode": "DE",
"diedCity": "Munich",
"gender": "male",
"prizes": [
{
"year": "1901",
"category": "physics",
"share": "1",
"motivation": "\"in recognition of the extraordinary services he has rendered by the discovery of the remarkable rays subsequently named after him\"",
"affiliations": [
{
"name": "Munich University",
"city": "Munich",
"country": "Germany"
}
]
}
]
},
{
"id": "996",
"firstname": "Robert",
"surname": "Wilson",
"born": "1937-05-16",
"died": "0000-00-00",
"bornCountry": "USA",
"bornCountryCode": "US",
"bornCity": "Geneva, NE",
"gender": "male",
"prizes": [
{
"year": "2020",
"category": "economics",
"share": "2",
"motivation": "\"for improvements to auction theory and inventions of new auction formats\"",
"affiliations": [
{
"name": "Stanford University",
"city": "Stanford, CA",
"country": "USA"
}
]
}
]
}
]
}
我在一个外部文件中有这个 JSON 以及许多条目。我找不到任何要弄清楚的文档。
解决方案
推荐阅读
- c# - 如何分别检查每个对象的验证?
- c# - Windows Server 2012:Powershell 无法识别 NuGet
- asp.net-core - WSO2 的 .net 核心身份验证提供程序
- c# - 如何在 C# 表单项目中执行多个批处理命令
- jquery - jQuery插件相对于插件位置设置图像src
- amazon-web-services - AWS S3 和 CloudFront 限制存储桶访问
- docker - Docker - 为每个单独的我的服务容器单独的 nginx 容器
- reactjs - 反应路由器 v4 参数未定义
- node.js - nodejs 工作线程可以用于执行长时间运行的基于文件 I/O 的 javascript 代码吗?
- android - android firebase putStream(): E/StorageException: 关闭 java.io.IOException: 关闭