在导出的Excel文件中显示错误

时间:2017-04-05 06:07:26

标签: mysql sql phpmyadmin

在phpmyadmin中执行以下查询,显示输出但导出的csv文件中显示sql错误。 这是查询:

SELECT engageboost_customers.`id`             AS User_ID, 
       Concat(`first_name`, ' ', `last_name`) AS Name, 
       `email`, 
       `phone`, 
       `created`                              AS Registration_date, 
       `lastlogin`, 
       Count(engageboost_ordermaster.id)      AS Total_Orders, 
       Max(created_date)                      AS Last_Order_Date, 
       Min(created_date)                      AS First_order_date, 
       Sum(paid_amount)                       AS Total_Amount_Paid, 
       CASE 
         WHEN `device_token_ios` IS NULL THEN 'NO' 
         WHEN `device_token_android` IS NULL THEN 'NO' 
         ELSE 'YES' 
       end                                    AS Active_App, 
       (SELECT CASE 
                 WHEN applied_coupon IS NULL THEN 'No' 
                 WHEN applied_coupon = '' THEN 'No' 
                 ELSE 'Yes' 
               end AS 'secound_order_copon' 
        FROM   engageboost_ordermaster 
        WHERE  engageboost_customers.id = engageboost_ordermaster.customer_id 
        LIMIT  1, 1)                          AS Secound_order_coupon_utilized, 
       (SELECT CASE 
                 WHEN applied_coupon IS NULL THEN 'No' 
                 WHEN applied_coupon = '' THEN 'No' 
                 ELSE 'Yes' 
               end AS 'secound_order_copon' 
        FROM   engageboost_ordermaster 
        WHERE  engageboost_customers.id = engageboost_ordermaster.customer_id 
        LIMIT  2, 1)                          AS Third_order_coupon_utilized, 
       (SELECT CASE 
                 WHEN engageboost_ordermaster.refferal_code = '' THEN 'No' 
                 WHEN engageboost_ordermaster.refferal_code IS NULL THEN 'No' 
                 ELSE engageboost_ordermaster.refferal_code 
               end AS refcode 
        FROM   engageboost_ordermaster 
        WHERE  engageboost_customers.id = engageboost_ordermaster.customer_id 
        LIMIT  0, 1)                          AS 'firstordersecode' 
FROM   `engageboost_customers` 
       LEFT OUTER JOIN engageboost_ordermaster 
                    ON engageboost_customers.id = 
                       engageboost_ordermaster.customer_id 
GROUP  BY engageboost_customers.id 

下面是我在csv文件中获得但输出显示的错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM' at line 1

1 个答案:

答案 0 :(得分:0)

你可以尝试这个,伙计:

SELECT 
    eo_1.`id` AS 'User_ID',
    CONCAT(ec.`first_name`, ' ', ec.`last_name`) AS 'Name',
    ec.`email`,
    ec.`phone`,
    ec.`created` AS 'Registration_date',
    ec.`lastlogin`,
    COUNT(eo_1.id) AS 'Total_Orders',
    MAX(ec.created_date) AS 'Last_Order_Date',
    MIN(ec.created_date) AS 'First_order_date',
    SUM(ec.paid_amount) AS 'Total_Amount_Paid',
    CASE
        WHEN ec.`device_token_ios` IS NULL THEN 'NO'
        WHEN ec.`device_token_android` IS NULL THEN 'NO'
        ELSE 'YES'
    END AS 'Active_App',
    eo_2.secound_order_copon AS 'Secound_order_coupon_utilized', 
    eo_3.secound_order_copon AS 'Third_order_coupon_utilized', 
    eo_4.refcode AS 'firstordersecode'
FROM
    engageboost_customers ec
    LEFT JOIN engageboost_ordermaster eo_1 ON eo_1.customer_id = ec.id
    LEFT JOIN (
        SELECT 
            customer_id,
            CASE
                WHEN applied_coupon IS NULL THEN 'No'
                WHEN applied_coupon = '' THEN 'No'
                ELSE 'Yes'
            END AS 'secound_order_copon'
        FROM engageboost_ordermaster
        LIMIT 1 , 1
    ) eo_2 ON eo_2.customer_id = ec.id
    LEFT JOIN (
        SELECT 
            customer_id,
            CASE
                WHEN applied_coupon IS NULL THEN 'No'
                WHEN applied_coupon = '' THEN 'No'
                ELSE 'Yes'
            END AS 'secound_order_copon'
        FROM engageboost_ordermaster
        LIMIT 2 , 1
    ) eo_3 ON eo_3.customer_id = ec.id
    LEFT JOIN (
        SELECT 
            customer_id,
            CASE
                WHEN engageboost_ordermaster.refferal_code = '' THEN 'No'
                WHEN engageboost_ordermaster.refferal_code IS NULL THEN 'No'
                ELSE engageboost_ordermaster.refferal_code
            END AS 'refcode'
        FROM engageboost_ordermaster
        LIMIT 0 , 1
    ) eo_4 ON eo_4.customer_id = ec.id
GROUP BY engageboost_customers.id;