2016-12-16 107 views
0

This查詢位於ColdFusion中,並且它可以爲舊版本的ColdFusion運行,但無法運行這個查詢現在。因爲它不是在聚合函數或領域GROUP BY子句列XXXXX'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中

 <CFQUERY name="getUserList" datasource="#REQUEST.dsn#" maxrows="1"> 
     SELECT 
      TUser.userID as user_ID, 
      Min(TUser.agencyID) as agencyID, 
      Min(TUser.servicing_EntityID) as servicing_EntityID, 
      Min(Tuser.userid) AS userID, 
      Min(Tuser.lastname) AS lastName, 
      Min(Tuser.firstname) AS firstName, 
      Min(Tuser.isSecondary) AS isSecondary, 
      Min(Tuser.corporate_ID) AS corporate_ID, 
      Min(Tuser.city) AS city, 
      Min(TUser.address1) AS address1, 
      Min(Corporate_Client.client_name) AS client_name, 
      Min(TLocationProvState.abrev) AS abrev, 
      TUser_Loyalty.loyalty_ID AS loyalty_ID 
     FROM TUser 
     LEFT JOIN TLocationProvState ON (Tuser.provinceID = TLocationProvState.PROVSTATEID) 
     LEFT JOIN Corporate_Client ON (Tuser.corporate_ID = Corporate_Client.client_ID) 
     LEFT JOIN TUser_Loyalty ON (Tuser.userid = TUser_Loyalty.userID) 
     LEFT JOIN TLoyalty ON (TUser_Loyalty.loyalty_ID = TLoyalty.loyalty_ID) 
     WHERE (0=1) 
     GROUP BY TUser.UserID, TUser_Loyalty.loyalty_ID 
     ORDER BY TUser.LastName, TUser.FirstName, TUser.User_ID 
     </CFQUERY> 
+0

將您的ORDER BY更改爲'ORDER BY LastName,firstName,User_ID',您將注意到您的選擇中有Min(LastName)和min(FirstName),這與Min的結果不同。由於表別名按順序可用,只需使用列別名即可。 – xQbert

+0

試過....它沒有工作,仍然是同樣的錯誤。而現在的SQL是GROUP BY TUser.UserID,TUser_Loyalty.loyalty_ID,TUser.LastName,TUser.FirstName \t \t ORDER BY USER_ID,loyalty_ID,姓氏,名字 –

+0

當我有奇怪的行爲,我只是不停地打破查詢...通過僅使用組中的TUser.userID,Tuser_Loyalty.Loyalty_ID來消除訂單,然後執行該操作?如果它運行,那麼順序是問題,我們集中在那裏,如果它仍然不運行消除分鐘和分組。它是否運行,然後在一分鐘內加回來,並通過... – xQbert

回答

0

您正試圖ORDER還沒有被指定爲包含只是讓我想起了列「TUser.LastName」在選擇列表中無效組字段。這些字段必須返回才能排序,因此,查詢執行程序需要知道如何處理分組語句中的所有字段。

GROUP BY TUser.UserID, TUser_Loyalty.loyalty_ID, TUser.LastName, TUser.FirstName 
ORDER BY TUser.User_ID, TUser.LastName, TUser.FirstName 

OR

GROUP BY TUser.UserID, TUser_Loyalty.loyalty_ID 
ORDER BY TUser.User_ID, MIN(TUser.LastName), MIN(TUser.FirstName) 
+0

謝謝,我會一一試一下,讓你知道結果。謝謝~~~ –

+0

其實,我不認爲任何形式的TUser表需要彙總。您已經通過UserID分組。這些字段在用戶標識中是統一的,對嗎? –

+0

嘗試了兩個...仍然是相同的錯誤...我想我應該使用別名按順序.... –

0

您的訂單將是無效的,由你使用的列,而不是分鐘名字的

WHERE (0=1) 
    GROUP BY TUser.UserID, TUser_Loyalty.loyalty_ID 
    ORDER BY LastName, FirstName, User_ID 

亦奇... 爲了別名Tuser.user_ID,但選擇顯示TUser.userID(無下劃線)

第e SQL具有select之後生成的順序,因此列別名可用。

+0

是的,我昨天嘗試。它說「不明確的列名lastname」或用戶名的東西... –

+0

你可以使用不同的別名,如aLastName和aFirstName? – xQbert

+0

只是在工作 –

相關問題