sql ,groupby分组后显示几列数据,

阅读更多
SELECT T.DEP_ID, to_char(trunc(to_date(t.option_time,'yyyy-mm-dd hh24:mi:ss'),'dd'),'yyyymmdd'),NVL(COUNT(T.OPTION_ID),0) AS ADDCOUNT
              FROM MST_USER_OPTION T
              WHERE T.OPTION_FLG != 0
              GROUP BY T.DEP_ID,to_char(trunc(to_date(t.option_time,'yyyy-mm-dd hh24:mi:ss'),'dd'),'yyyymmdd')
              ORDER BY ADDCOUNT

trunc是截断数据,把日期截断成了,天相等的, 防止天和groupby T.DEP_ID  发生冲突.

你可能感兴趣的:(SQL)