今天碰到一个问题,如下。
SQL1:
SELECT bookingParty.NAME AS CARRIER_NAME,container.TYPE AS CONTAINER_TYPE,
COUNT(container.TYPE) AS COUNT FROM SO_SHIPPING_ORDER so INNER JOIN CO_CONTAINER container
on so.ID = container.ORDER_ID , BD_OCEAN_CARRIER_CODE bookingParty
WHERE 1=1 AND so.ORDER_TYPE='10' AND so.STATUS='3' AND so.BUSINESS_TYPE='101'
AND bookingParty.ID=so.CARRIER_ID
group by bookingParty.NAME,container.TYPE
SQL2:
SELECT bookingParty.NAME AS CARRIER_NAME,container.TYPE AS CONTAINER_TYPE,COUNT(container.TYPE)
AS CONTAINER_COUNT,container.VOLUME AS VOLUME,SUM(container.WEIGHT) AS WEIGHT
FROM SO_SHIPPING_ORDER so INNER JOIN CO_CONTAINER container on so.ID = container.ORDER_ID ,
BD_OCEAN_CARRIER_CODE bookingParty WHERE 1=1 AND so.ORDER_TYPE='10' AND so.STATUS='3'
AND so.BUSINESS_TYPE='101' AND bookingParty.ID=so.CARRIER_ID
group by bookingParty.NAME,container.TYPE,container.VOLUME
SQL1执行结果是先对container.TYPE进行分组,在对名称进行分组;而SQL2执行结果是按group by后字段顺序进行分组。
如果在SQL1后加上order by bookingParty.NAME的话,执行结果则是按照group by后字段顺序进行分组。
==>sql语句group by的顺序问题,是有默认顺序还是随机?