SQLSTATE [HY000]:常规错误:1267排序规则的非法混合

时间:2019-07-09 05:36:07

标签: mysql sql stored-procedures collation

正如标题所述,我在查询时遇到了麻烦;

我尝试过更改temp_ob的排序规则以达到相同的效果。

请告知如何解决此问题。

请注意,我将在存储过程中使用它。

   $.get(newUrl, function (data) {
    $("#ProductsPartialView").empty();
    $("#ProductsPartialView").append(data);
    $('#loadingModal').modal('hide');

}).fail(function (xhr, err) {
    alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
    alert("responseText: " + xhr.responseText);
});

MYSQL版本 8.0.16

默认排序规则 utf8mb4_0900_ai_ci

默认字符集 utf8mb4

表排序规则 utf8mb4_unicode_ci

在Mysql Workbench中运行查询时收到的错误

DROP  TABLE IF EXISTS  temp_ob;
CREATE  TABLE temp_ob
SELECT 
    a.id,"2019-06-01" as created_at,"Opening",(coalesce(b.receiving,0) + coalesce(c.mrfd,0) - coalesce(d.issued,0)) As opening_balance,0 as grir,0 as mrfd,0 as issued,b.plant_id,"OB" as type
FROM
    (items AS a
        LEFT JOIN
            (SELECT 
                item_id, SUM(quantity) AS receiving,plant_id
            FROM
                article_receives
            WHERE
                created_at <= "2019-06-01" 
            GROUP BY item_id) b ON a.id = b.item_id
        LEFT JOIN
            (SELECT 
                item_id, SUM(quantity) AS mrfd
            FROM
                mrfd_details
            WHERE
                created_at <= "2019-06-01"  
            GROUP BY item_id) c ON a.id = c.item_id
        LEFT JOIN
            (SELECT 
                item_id, SUM(quantity) AS issued
            FROM
                article_issues
            WHERE
                created_at <= "2019-06-01"
            GROUP BY item_id) d ON a.id = d.item_id

) WHERE a.id= 'GRL0170' ;

SELECT 
    *
FROM 
(
SELECT * 
FROM temp_ob
UNION
SELECT item_id,created_at,issuance_id,0 as ob,0 as grir,0 as mrfd,quantity,plant_id,"ISSUE" as "type"
FROM article_issues AS a 
UNION 
SELECT b.item_id,b.created_at,cr.demand_id,0 as ob,b.quantity,0 as mrfd,0 as issue,b.plant_id,"RECEVIE" as "type"
FROM article_receives AS b
    left join completed_receives AS cr on b.transaction_id = cr.purchase_id
UNION 
SELECT item_id,created_at,mrfd_id,0 as ob,0 as grir,quantity,0 as issue,plant_id,"MRFD" as "type"
FROM mrfd_details AS c
) AS u
LEFT JOIN (SELECT id,title,sku_id FROM items) AS z ON u.id = z.id
LEFT JOIN (SELECT id,title FROM skus) AS y ON z.sku_id = y.id
WHERE 
    u.id = 'GRL0170' 
    AND created_at BETWEEN '2019-06-01' AND DATE_ADD('2019-06-30', INTERVAL 1 DAY)
ORDER BY 
    u.created_at;

在Laravel中使用时出错

Error Code: 1271. Illegal mix of collations for operation 'UNION'

0 个答案:

没有答案