坏细木工:从连接中选择时出错

时间:2018-02-12 11:22:36

标签: sql join sql-server-2016

我正在尝试创建一个每小时的调度报告,因此对于“每小时”部分(在SQL Server 2016中)我试图对每个小时进行查询并加入它们但我得到的错误我无法理解查询是这样的:

Select
*
From
(SELECT
  PackageCategory + ' Count ' + Cast (Count (UpdatedBy) as varchar) as '9 to 10'
from
  [order] o
  LEFT OUTER JOIN Order_LifeHistory h ON o.pkOrderID = h.fkOrderId
  LEFT OUTER JOIN PackageGroups pg ON o.fkPackagingGroupId = pg.PackageCategoryID
Where
  datepart(hour, dprocessedon) between 9
  and 10
group by
  PackageCategory
) as firstset
FULL JOIN (
SELECT
  PackageCategory + ' Count ' + Cast (Count (UpdatedBy) as varchar) as '9 to 10'
from
  [order] o
  LEFT OUTER JOIN Order_LifeHistory h ON o.pkOrderID = h.fkOrderId
  LEFT OUTER JOIN PackageGroups pg ON o.fkPackagingGroupId = pg.PackageCategoryID
Where
  datepart(hour, dprocessedon) between 10
  and 11
group by
  PackageCategory
)as secondset on firstset.PackageCategory + ' Count ' + Cast (Count (UpdatedBy) as varchar) = secondset.PackageCategory + ' Count ' + Cast (Count (UpdatedBy) as varchar)

我不断收到以下错误:

无效的列名'PackageCategory' 列名称“UpdatedBy”无效。
列名称'PackageCategory'无效。
列名称“UpdatedBy”无效。

我无法理解这一点,因为我加入的每个查询都是独立工作的 我错过了一些明显的东西吗? 请原谅我的工作,我是一个非常新的人,并倾向于使用弗兰肯斯坦的方法来编写查询(挖掘其他人的点点滴滴将它们连接在一起,并希望有一个隐喻的闪电) 谢谢你的阅读

2 个答案:

答案 0 :(得分:0)

因为您的// In index.js const functions = require('firebase-functions'); const admin = require('firebase-admin'); const express = require("express") const myApi = require("./api/my") admin.initializeApp(functions.config().firebase); const app = express(); app.use("/api/my", myApi.myRouter); // In ./api/my/index.js const myRouter = express.Router(); myRouter.get('/account', function(req, res) { admin.auth().... <- Need to use the previously configured admin here } firstset不包含这些列。 它们都只包含一个名为secondset的列。

您的完整加入9 to 10条款应为on

firstset.[9 to 10] = secondset.[9 to 10]

答案 1 :(得分:0)

您未选择array<System::String ^> ^args = System::Environment::GetCommandLineArgs(); ,而是将其选择的值加上其他字符串作为名为PackageCategory的列。再想一想它:

9 to 10

您的选择中没有名为SELECT PackageCategory + ' Count ' + Cast (Count (UpdatedBy) as varchar) as '9 to 10' PackageCategory的列。