获取查询查询错误

时间:2014-01-20 05:43:06

标签: mysql coldfusion coldfusion-9

我正在使用以下代码并想知道为什么我收到“Queries of Queries”错误?

<cfquery name="findpercentage" datasource="#mydatasource#">

    SELECT  
         Count(TableId_bi) AS Total_Events
            ,Sum(CASE WHEN 'OPEN'       =   Event_vch THEN 100 END) / Count(*) AS OPENS
            ,Sum(CASE WHEN 'BOUNCE'     =   Event_vch THEN 100 END) / Count(*) AS BOUNCE
            ,Sum(CASE WHEN 'DEFERRED'   =   Event_vch THEN 100 END) / Count(*) AS DEFERRED
            ,Sum(CASE WHEN 'DROPPED'    =   Event_vch THEN 100 END) / Count(*) AS DROPPED
            ,Sum(CASE WHEN 'DELIVERED'  =   Event_vch THEN 100 END) / Count(*) AS DELIVERED
            ,Sum(CASE WHEN 'PROCESSED'  =   Event_vch THEN 100 END) / Count(*) AS PROCESSED
            ,Sum(CASE WHEN 'SPAMREPORT' =   Event_vch THEN 100 END) / Count(*) AS SPAMREPORT 
    FROM    
            mydatabase;


    </cfquery>


<cfdump var="#findpercentage#">



<cfquery name = "piechartdisplay" dbtype = "query">

SELECT OPENS as Ecount, 'Open' as type
from findpercentage

UNION

SELECT BOUNCE as Ecount, 'Bounce' as type
from findpercentage

UNION

SELECT DEFERRED as Ecount, 'Deferred' as type
from findpercentage

UNION

SELECT DROPPED as Ecount, 'Dropped' as type
from findpercentage

UNION

SELECT DELIVERED as Ecount, 'Delivered' as type
from findpercentage

UNION

SELECT PROCESSED as Ecount, 'Processed' as type
from findpercentage

UNION


SELECT SPAMREPORT as Ecount, 'Spamreport' as type
from findpercentage



</cfquery>




<cfdump var="#piechartdisplay#">

查询的第一部分是在网页上转储属性,但是,“piechartdisplay”的第二次转储尝试正在生成查询或查询错误。错误描述如下:

Error Executing Database Query.

Query Of Queries syntax error.
Encountered "DEFERRED. Incorrect Select List, Incorrect select column,

The error occurred in C:\Path\myfile.cfm: line 39

37 : 
38 : 
39 : <cfquery name = "piechartdisplay" dbtype = "query">
40 : 
41 : SELECT OPENS as Ecount, 'Open' as type
SQL    SELECT OPENS as Ecount, 'Open' as type from findpercentage UNION SELECT BOUNCE as Ecount, 'Bounce' as type from findpercentage UNION SELECT DEFERRED as Ecount, 'Deferred' as type from findpercentage UNION SELECT DROPPED as Ecount, 'Dropped' as type from findpercentage UNION SELECT DELIVERED as Ecount, 'Delivered' as type from findpercentage UNION SELECT PROCESSED as Ecount, 'Processed' as type from findpercentage UNION SELECT SPAMREPORT as Ecount, 'Spamreport' as type from findpercentage

我必须从上面的查询中传递数据(在它开始运行之后没有错误),如下所示,这就是我编写上述QoQ的原因:

<cfset dataItem =[
            '#type#', '#Ecount#'
        ]>

请告诉我这里的错误。

1 个答案:

答案 0 :(得分:5)

正如错误所暗示的那样,deferred是一个保留字(“Reserved words in queries”)。将其替换为原始查询中的其他内容,或尝试在QoQ中使用方括号转义它。