由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - PIVOT, 请大拿,帮我debug
相关主题
请帮我查一段pivot code 错在哪里?怎么写个query 把输出变成横排.
better solution for cross table query in sql?面试中的一道sql的题目。
再来一个SQL Server的面试题any informix high hand here? sql need help here.
我的这句MySQL哪里错了吗?问个查询的问题
问一个SQL Server的问题change year format in Access by SQL query (转载)
help needed on aspx&ms-accesserror of sql query in MS Access database (转载)
A sql questionHelp on Oracle Query
error run SQL query from pyodbc python 3.2.5 (转载)T-SQL Row Concatenate with a Twist??
相关话题的讨论汇总
话题: month话题: pivot话题: select
进入Database版参与讨论
1 (共1页)
z**********8
发帖数: 2049
1
SELECT RecordSourceID, [1] AS JAN, [2] AS FEB, [3] AS MAR, [4] AS APR, [5]
AS MAY, [6] AS JUN, [7] AS JUL, [8] AS AUG, [9] AS SEP, [10] AS OCT, [11] AS
NOV, [12] AS DEC
FROM
(SELECT personid, Month(DateEntered), RecordSourceID
FROM dbo.tblPerson
WHERE RecordSourceID BETWEEN 152 AND 162 AND LoginPass IS NOT NULL AND year(
DateEntered)=2013) p
pivot
(
COUNT (personid)
FOR MONTH(DATEENTERED) IN
( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12])
)AS pvt
结果出不来啊。
Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near 'pivot'.
谢谢先!
z**********8
发帖数: 2049
2
outcome is like this as below, (in ms sql server)
Recordsourceid, JAN, FEB, ..., DEC
152 50 30 10
153 20 33 5
154 .
.
.
.
162
B*****g
发帖数: 34098
3
try give an alias for Month(DateEntered) in select then use it in for

AS
year(

【在 z**********8 的大作中提到】
: SELECT RecordSourceID, [1] AS JAN, [2] AS FEB, [3] AS MAR, [4] AS APR, [5]
: AS MAY, [6] AS JUN, [7] AS JUL, [8] AS AUG, [9] AS SEP, [10] AS OCT, [11] AS
: NOV, [12] AS DEC
: FROM
: (SELECT personid, Month(DateEntered), RecordSourceID
: FROM dbo.tblPerson
: WHERE RecordSourceID BETWEEN 152 AND 162 AND LoginPass IS NOT NULL AND year(
: DateEntered)=2013) p
: pivot
: (

z**********8
发帖数: 2049
4
i tried it first.However it did not work either. so frustrated.
Month(dateentered) AS Months
thanks.
B*****g
发帖数: 34098
5
also: FOR MONTH(DATEENTERED) ==> FOR Months

【在 z**********8 的大作中提到】
: i tried it first.However it did not work either. so frustrated.
: Month(dateentered) AS Months
: thanks.

1 (共1页)
进入Database版参与讨论
相关主题
T-SQL Row Concatenate with a Twist??问一个SQL Server的问题
问个SQL问题help needed on aspx&ms-access
请问这个update query有什么问题?A sql question
求教个MS SQL的问题error run SQL query from pyodbc python 3.2.5 (转载)
请帮我查一段pivot code 错在哪里?怎么写个query 把输出变成横排.
better solution for cross table query in sql?面试中的一道sql的题目。
再来一个SQL Server的面试题any informix high hand here? sql need help here.
我的这句MySQL哪里错了吗?问个查询的问题
相关话题的讨论汇总
话题: month话题: pivot话题: select