【发布时间】:2014-06-10 14:06:12
【问题描述】:
Select CorpID,
Convert(VarChar(2),Month(E.BeginDate)) + '/' + Convert(VarChar(4),Year(E.BeginDate)),
Count(Year(e.BeginDate)) As 'total Screen'
--Count(Month(E.CurrentBeginDate))
From dbo.NonCalls E
Where E.BeginDate between {d'2013-01-01'} and {d'2013-12-31'}
Group By CorpID, Year(E.BeginDate),Month(E.BeginDate)
Union ALL
Select CorpID,
Convert(VarChar(2),Month(E.CurrentBeginDate)) + '/' + Convert(VarChar(4),Year(E.CurrentBeginDate)),
Count(Year(e.CurrentBeginDate)) As 'total Screen'
--Count(Month(E.CurrentBeginDate))
From dbo.Employee E
Where E.CurrentBeginDate between {d'2013-01-01'} and {d'2013-12-31'}
Group By CorpID, Year(E.CurrentBeginDate),Month(E.CurrentBeginDate)
--Order By CorpID, Year(E.CurrentBeginDate), Month(E.CurrentBeginDate)
我将我的代码更改为这个,现在我得到了我正在寻找的数字,唯一的问题是它没有排序我需要它按 Corpid 排序,然后按日期 01-02-03 等我不太确定
how to get that accomplish any help would be greatly apreciated.
【问题讨论】:
-
错误信息是?你用的是什么数据库?
-
Msg 205,级别 16,状态 1,行 1 所有使用 UNION、INTERSECT 或 EXCEPT 运算符组合的查询必须在其目标列表中具有相同数量的表达式。数据库是 SQL
-
@user3571281 - “SQL” 不是数据库,它是多个数据库实现的标准化语言。这就像去杂货店看冰淇淋——Dreyer's 有香草味,Costco、Haagen Daz、Ben & Jerry's 等也有。哦,它们都有微妙的不同。不要包含注释掉的代码 - 它不应该运行并且只会混淆事物,因此不会带来好处。 (从您的查询中消除它也会导致它运行吗?)。您的查询似乎不会以会引发给定错误的方式无效。
标签: sql sql-server