发布网友 发布时间:2022-04-24 12:02
共1个回答
热心网友 时间:2022-04-08 08:20
年:
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy');
月:
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm');
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymm');
日:
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd');
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmdd');
时:
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24');
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24');
分:
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi');
group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24mi');
秒:
group by sysdate;追问我是想按年月日分组 不是分开分组 字段名是shijian
追答group by to_char(to_date(shijian, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd');
如:[2015-07-23 14:33:56 ]
[2015-07-23 14:34:04]
[2015-07-21 14:33:56]
[2015-07-22 14:34:04]
分组后:
[2015-07-21]
[2015-07-22]
[2015-07-23]
代码示例:SHIJIAN字段是格式(yyyy-mm-dd hh24:mi:ss)
SELECT ID,NAME,SEX,SHIJIAN FROM 表;
转换后:
SELECT ID,NAME,SEX,
to_char(to_date(shijian, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd') AS "SHIJIAN"
FROM 表;
或:(shijian类型为timedate类型)
SELECT ID,NAME,SEX,to_char(shijian,'yyyy-mm-dd') AS "SHIJIAN" FROM 表;