为什么两个相同的查询语句有不同的结果

时间:2018-03-14 10:14:38

标签: mysql

这是我的查询声明。它们相似但执行时的结果不同。根据我的ORDER BY子句,这两个结果都是有效的。但label_total列中的顺序不相同

- 第一个SQL语句

SELECT
    labels.production_line_id,
    prices.`code`,
    labels.quantity,
    `labels`.`total` AS `label_total` 
FROM
    `labels`
    INNER JOIN `order_details` ON `labels`.`order_detail_id` = `order_details`.`id` 
    AND `order_details`.`deleted_at` IS NULL
    INNER JOIN `prices` ON `prices`.`id` = `order_details`.`price_id` 
    AND `prices`.`deleted_at` IS NULL 
WHERE
    `order_details`.`order_id` IN ( '2452' ) 
    AND `labels`.`type` = '0' 
    AND `labels`.`status` != '7' 
    AND `labels`.`status` != '8' 
ORDER BY
    `labels`.`production_line_id` ASC,
    `prices`.`code` ASC,
    `labels`.`quantity` DESC

- 第二次

SELECT
    labels.production_line_id,
    prices.`code`,
    labels.quantity,
    `labels`.`total` AS `label_total` 
FROM
    `labels`
    INNER JOIN `order_details` ON `labels`.`order_detail_id` = `order_details`.`id` 
    AND `order_details`.`deleted_at` IS NULL 
    INNER JOIN `prices` ON `prices`.`id` = `order_details`.`price_id` 
    AND `prices`.`deleted_at` IS NULL 
WHERE
    `order_details`.`order_id` IN ( '2452' ) 
    AND `labels`.`type` = '0' 
    AND `labels`.`status` != '7' 
    AND `labels`.`status` != '8' 
ORDER BY
    labels.production_line_id ASC,
    prices.`code` ASC,
    labels.quantity DESC

结果

enter image description here

0 个答案:

没有答案