gpt4 book ai didi

sql - Red Query Builder生成哪种类型的SQL?

转载 作者:行者123 更新时间:2023-12-03 19:50:32 24 4
gpt4 key购买 nike

我一直在尝试在项目上使用Red Query Builder可视查询生成器,但我们发现SQL输出与数据库(SQLite)期望的SQL不一致。这使我想知道正在生成哪种SQL语言,以及如何更改它?

编辑:

例如,这是一条生成的SQL行。

"SELECT \"x0\".\"ID\", \"x0\".\"NAME\", \"x0\".\"COUNTRYCODE\", \"x0\".\"DISTRICT\", \"x0\".\"POPULATION\" FROM \"CITY\" \"x0\" INNER JOIN \"COUNTRY\" \"x1\" ON \"x0\".\"COUNTRYCODE\" = \"x1\".\"CODE\" WHERE (\"x1\".\"NAME\" = ?)"


从粗略的检查来看,x0似乎是名为CITY的表的别名,但是该连接是在哪里进行的呢?

最佳答案

创建适当的表后,查询对于SQLite来说对我来说运行得很好。这是未转义和格式化的完整查询:

SELECT 
"x0"."ID",
"x0"."NAME",
"x0"."COUNTRYCODE",
"x0"."DISTRICT",
"x0"."POPULATION"
FROM
"CITY" "x0"
INNER JOIN
"COUNTRY" "x1"
ON
"x0"."COUNTRYCODE" = "x1"."CODE"
WHERE ("x1"."NAME" = ?)


这是DDL,并进行插入测试:

CREATE TABLE Country (CODE text, Name Text);
CREATE TABLE CITY (ID int, Name text, countrycode text, district text, population int);

INSERT INTO Country VALUES ('US', 'United States');
INSERT INTO Country VALUES ('AU', 'Australia');

INSERT INTO City VALUES (1, 'Albany', 'US', 'NY', 1000000);
INSERT INTO City VALUES (2, 'Atlanta', 'US', 'GA', 2000000);
INSERT INTO City VALUES (3, 'Washington', 'US', 'DC', 500000);
INSERT INTO City VALUES (4, 'Melborne', 'AU', 'A', 40000);
INSERT INTO City VALUES (5, 'Sydney', 'AU', 'B', 60000);


完整示例(在控制台中运行,因此未对查询进行参数化,但是SQLite接受 ?进行参数化)。

C:\Windows\System32>sqlite3
SQLite version 3.7.6.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE Country (CODE text, Name Text);
sqlite> CREATE TABLE CITY (ID int, Name text, countrycode text, district text, population int);
sqlite> INSERT INTO Country VALUES ('US', 'United States');
sqlite> INSERT INTO Country VALUES ('AU', 'Australia');
sqlite> INSERT INTO City VALUES (1, 'Albany', 'US', 'NY', 1000000);
sqlite> INSERT INTO City VALUES (2, 'Atlanta', 'US', 'GA', 2000000);
sqlite> INSERT INTO City VALUES (3, 'Washington', 'US', 'DC', 500000);
sqlite> INSERT INTO City VALUES (4, 'Melborne', 'AU', 'A', 40000);
sqlite> INSERT INTO City VALUES (5, 'Sydney', 'AU', 'B', 60000);
sqlite> SELECT
...> "x0"."ID",
...> "x0"."NAME",
...> "x0"."COUNTRYCODE",
...> "x0"."DISTRICT",
...> "x0"."POPULATION"
...> FROM
...> "CITY" "x0"
...> INNER JOIN
...> "COUNTRY" "x1"
...> ON
...> "x0"."COUNTRYCODE" = "x1"."CODE"
...> WHERE ("x1"."NAME" = 'United States');
1|Albany|US|NY|1000000
2|Atlanta|US|GA|2000000
3|Washington|US|DC|500000
sqlite>

关于sql - Red Query Builder生成哪种类型的SQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16744780/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com