I am trying to get a horizontal output of the data in format
我试图以格式获得数据的水平输出
The query is:
查询是:
SELECT RDT1.County_Name
,RDT1.DistributionNumber as Dist_No
,RDT1.Vac_Allocated
,RDT1.Priority,RDT2.DistributionNumber as Dist_No
,RDT2.Vac_Allocated as Vac_Allocated
,RDT3.DistributionNumber as Dist_No
,RDT3.Vac_Allocated as Vac_Allocated
FROM Result_Distribution_Table AS RDT1
,Result_Distribution_Table AS RDT2
,Result_Distribution_Table AS RDT3
WHERE RDT1.County_Name = RDT2.County_Name AND
RDT1.DistributionNumber = 1 AND
RDT2.DistributionNumber = 2 AND
RDT3.DistributionNumber = 3 AND
RDT1.County_Name = RDT3.County_Name
WHERE Solution_id= "10"
When I execute this query, I get a response
当我执行此查询时,我得到一个响应
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Solution_id" could not be bound.消息4104,级别16,状态1,行1无法绑定多部分标识符“Solution_id”。
Solution_id
is a column in the Result_Distribution_Table
table.
Solution_id是Result_Distribution_Table表中的一列。
Please help as to what i am doing wrong and what is the solution?
请帮助我做错了什么,解决方案是什么?
2 个解决方案
#1
3
You can have only one WHERE
clause per query. Also avoid using old style joining instead use JOIN
. NOTE: fill the correct table alies for the solution_id
col.
每个查询只能有一个WHERE子句。也避免使用旧式连接而是使用JOIN。注意:填写solution_id col的正确表格。
SELECT RDT1.County_Name
,RDT1.DistributionNumber as Dist_No
,RDT1.Vac_Allocated
,RDT1.Priority,RDT2.DistributionNumber as Dist_No
,RDT2.Vac_Allocated as Vac_Allocated
,RDT3.DistributionNumber as Dist_No
,RDT3.Vac_Allocated as Vac_Allocated
FROM Result_Distribution_Table RDT1 JOIN Result_Distribution_Table RDT2
ON RDT1.County_Name = RDT2.County_Name JOIN Result_Distribution_Table RDT3
ON RDT1.County_Name = RDT3.County_Name
WHERE RDT1.DistributionNumber = 1 AND
RDT2.DistributionNumber = 2 AND
RDT3.DistributionNumber = 3 AND
[...].Solution_id= "10"
ADDING: Just noticed that you are using same table 3 times. If it is the case you can get the same results as;
添加:刚刚注意到您使用了相同的表3次。如果是这种情况,您可以得到相同的结果;
SELECT County_Name
,DistributionNumber as Dist_No
,Vac_Allocated
,Priority,RDT2.DistributionNumber as Dist_No
,Vac_Allocated as Vac_Allocated
,DistributionNumber as Dist_No
,Vac_Allocated as Vac_Allocated
FROM Result_Distribution_Table
WHERE DistributionNumber IN (1,2,3) AND
Solution_id= "10"
#2
0
The issue is because there is no table in the query:
问题是因为查询中没有表:
It looks like you forgot to include the table in your query.
您似乎忘记在查询中包含该表。
#1
3
You can have only one WHERE
clause per query. Also avoid using old style joining instead use JOIN
. NOTE: fill the correct table alies for the solution_id
col.
每个查询只能有一个WHERE子句。也避免使用旧式连接而是使用JOIN。注意:填写solution_id col的正确表格。
SELECT RDT1.County_Name
,RDT1.DistributionNumber as Dist_No
,RDT1.Vac_Allocated
,RDT1.Priority,RDT2.DistributionNumber as Dist_No
,RDT2.Vac_Allocated as Vac_Allocated
,RDT3.DistributionNumber as Dist_No
,RDT3.Vac_Allocated as Vac_Allocated
FROM Result_Distribution_Table RDT1 JOIN Result_Distribution_Table RDT2
ON RDT1.County_Name = RDT2.County_Name JOIN Result_Distribution_Table RDT3
ON RDT1.County_Name = RDT3.County_Name
WHERE RDT1.DistributionNumber = 1 AND
RDT2.DistributionNumber = 2 AND
RDT3.DistributionNumber = 3 AND
[...].Solution_id= "10"
ADDING: Just noticed that you are using same table 3 times. If it is the case you can get the same results as;
添加:刚刚注意到您使用了相同的表3次。如果是这种情况,您可以得到相同的结果;
SELECT County_Name
,DistributionNumber as Dist_No
,Vac_Allocated
,Priority,RDT2.DistributionNumber as Dist_No
,Vac_Allocated as Vac_Allocated
,DistributionNumber as Dist_No
,Vac_Allocated as Vac_Allocated
FROM Result_Distribution_Table
WHERE DistributionNumber IN (1,2,3) AND
Solution_id= "10"
#2
0
The issue is because there is no table in the query:
问题是因为查询中没有表:
It looks like you forgot to include the table in your query.
您似乎忘记在查询中包含该表。