我正在尝试编写以下语句是我想要的输出:
SELECT TABLE1.COLUMN_1
FROM (SELECT '0' AS COLUMN_1 FROM DUAL) TABLE1,
(SELECT '0' AS COLUMN_1 FROM DUAL) TABLE2
WHERE TABLE1.COLUMN_1 = TABLE2.COLUMN_1;
这是代码 SQLKata:
<PackageReference Include="SqlKata" Version="3.2.3" />
<PackageReference Include="SqlKata.Execution" Version="3.2.3" />
using SqlKata;
using SqlKata.Execution;
var q1= new Query("DUAL").Select("'0' AS COLUMN_1");
var q2= new Query("DUAL").Select("'0' AS COLUMN_1");
var q3= new Query().From(q1, "table1")
.From(q2, "table2")
.Where("table1.COLUMN_1","table2.COLUMN_1")
.Select("table1.COLUMN_1")
.FirstOrDefault<string>();
这导致:
SELECT TABLE1.COLUMN_1
FROM (SELECT '0' AS COLUMN_1 FROM DUAL) TABLE2
WHERE TABLE1.COLUMN_1 = TABLE2.COLUMN_1;
看起来第二个 From 覆盖了第一个 From。
另一个例子:
var phones = new Query("Phones");
var laptops = new Query("Laptops");
var query = new Query().From(phones, "P").From(laptops, "L")
结果,通知 Phones 不在查询中:
SELECT
*
FROM
(
SELECT
*
FROM
[Laptops]
) AS [L]