结果未按要求排序

时间:2015-03-24 03:10:44

标签: mysql sql sql-server oracle oracle11g

我有两个数据库。一个oracle和一个sql server。 对于oracle。

WITH cycleset AS (
SELECT 
 c.CYCLE_OID
, UPPER(m.NAME) AS MACHINE_NAME, c.PAYLOAD
FROM  mshist.CYCLE c
INNER JOIN msmodel.MACHINE m ON m.machine_oid = c.primarymachine
WHERE (c.CYCLE_OID BETWEEN 1705497113111 AND 1705497596716)),

eventset AS (
SELECT cs.* ,
  CAST((
      EXTRACT(SECOND FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) + 
      EXTRACT(MINUTE FROM ( a.END_TIME_UTC- a.START_TIME_UTC) DAY TO SECOND) * 60 +
      EXTRACT(HOUR FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) * 60 * 60 +
      EXTRACT(DAY FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) * 60 * 60 * 24 
      ) AS NUMBER(19,0)) AS DURATION
FROM  cycleset cs
INNER JOIN mshist.CYCLEACTIVITYCOMPONENT a ON cs.CYCLE_OID = a.OID
WHERE a.NAME NOT IN ('Machine.Delay')
UNION ALL
SELECT cs.* ,
  CAST((
      EXTRACT(SECOND FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) + 
      EXTRACT(MINUTE FROM ( a.END_TIME_UTC- a.START_TIME_UTC) DAY TO SECOND) * 60 +
      EXTRACT(HOUR FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) * 60 * 60 +
      EXTRACT(DAY FROM ( a.END_TIME_UTC - a.START_TIME_UTC) DAY TO SECOND) * 60 * 60 * 24 
      ) AS NUMBER(19,0)) AS DURATION
 FROM  cycleset cs
INNER JOIN mshist.CYCLEDELAY a ON cs.CYCLE_OID = a.OID)

SELECT MACHINE_NAME, SUM(DURATION) AS EVENT_DURATION, SUM(PAYLOAD) AS      PAYLOAD
FROM eventset
GROUP BY 
MACHINE_NAME

对于SQL。

SELECT  
  UPPER(MACH_NAME) AS MACHINE_NAME
 , CAST(SUM(f.SPLIT_DURATION) AS NUMERIC(19,0) ) AS DURATION,
SUM(f.EVENT_PAYLOAD) AS PAYLOAD
FROM [mssol2015pdw].[dbo].[F_CYCLE_SHIFT_HR_EVENT_LU] f
INNER JOIN [mssol2015pdw].[dbo].D_MACHINE m ON f.MACHINE_1_DIM_KEY =     m.DIMENSION_KEY
INNER JOIN [mssol2015pdw].[dbo].D_CYCLE c ON f.[CYCLE_DIM_KEY] = c.DIMENSION_KEY
WHERE m.DIMENSION_KEY > 0
AND c.CYCLE_OID BETWEEN 1705497113111 AND 1705497596716
GROUP BY UPPER(MACH_NAME)

数据应按机器名称排序,它在oracle中排序,但不在sql中排序。 我试图比较两列中的数据是否相同。 两个查询的数据计数也不相同。

1 个答案:

答案 0 :(得分:1)

只需将Order by MACHINE_NAME添加到您的两个查询的末尾,您也可以在查询结尾处添加Order by 1,因为MACHINE_NAME是第一个字段