为所附查询提取分钟

时间:2019-02-03 14:21:38

标签: sql

我有以下查询工作正常。

但是,我希望附件中显示的列仅将时间显示为“分钟”。

请有人可以建议我该怎么做吗? 再次感谢您的帮助!

enter image description here

USE CBS_AFRICA_LIVECOPY

SELECT FOLIO_NUMBER, FORMAT(ORDER_ENTRY_TIME, 'hh:MM') AS ORDER_ENTRY_TIME, 
    FORMAT(START_LOAD_TIME, 'hh:MM') as START_LOAD_TIME, 
    (ORDER_ENTRY_TIME - START_LOAD_TIME) AS STAGING_MINUTES, 
    (TERM_END_LOAD_TIME - START_LOAD_TIME) AS LOADING_MINUTES,
    (TERM_END_LOAD_TIME - ORDER_ENTRY_TIME) AS TERMINAL_MINUTES,
    FORMAT(TERM_END_LOAD_TIME, 'hh:MM') as TERM_END_LOAD 
FROM ORDERS    
WHERE LOADING_TERMINAL_ID = '11011'

1 个答案:

答案 0 :(得分:0)

您应该使用DATEPART()DATETIME中提取分钟:

USE CBS_AFRICA_LIVECOPY;

SELECT FOLIO_NUMBER, FORMAT(ORDER_ENTRY_TIME, 'hh:MM') AS ORDER_ENTRY_TIME, 
    FORMAT(START_LOAD_TIME, 'hh:MM') as START_LOAD_TIME, 
    DATEPART(MINUTE, (ORDER_ENTRY_TIME - START_LOAD_TIME) AS STAGING_MINUTES, 
    DATEPART(MINUTE, (TERM_END_LOAD_TIME - START_LOAD_TIME)) AS LOADING_MINUTES,
    DATEPART(MINUTE, (TERM_END_LOAD_TIME - ORDER_ENTRY_TIME)) AS TERMINAL_MINUTES,
    FORMAT(TERM_END_LOAD_TIME, 'hh:MM') as TERM_END_LOAD 
FROM ORDERS    
WHERE LOADING_TERMINAL_ID = '11011';

如果您使用的是MySQL,则可以使用EXTRACT函数。