收藏文章 楼主

sql 获取系统时间和表里面的时间列

版块:mysql 数据库通用基础大全   类型:精华   作者:小绿叶技术博客   查看:2961   回复:0   获赞:2   时间:2019-09-16 10:30:48

------------ 获取系统时间  --------------

select GETDATE() as '当前日期时间',

DateName(year,GetDate())+'-'+DateName(month,GetDate())+'-'+DateName(day,GetDate()) as '当前日期', 

DateName(quarter,GetDate()) as '第几季度',

DateName(week,GetDate()) as '一年中的第几周',

DateName(DAYOFYEAR,GetDate()) as '一年中的第几天',

DateName(year,GetDate()) as '年',

DateName(month,GetDate()) as '月',

DateName(day,GetDate()) as '日',

DateName(hour,GetDate()) as '时',

DateName(minute,GetDate()) as '分',

DateName(second,GetDate()) as '秒',

DateName(MILLISECOND,GetDate()) as '豪秒',

DateName(WEEKDAY,GetDate()) as '星期几'


------------  获取表里面的时间  ---------------

select year(a.CreateDate) as 年, -- 使用 yesr() 函数获取年份

month(a.CreateDate) as 月, -- 使用 month() 获取月份

count(a.WorkcenterName) as 数量 -- 计算要统计的列,(总数太多,下面的group by 分组统计对应的月份的数量)

--要显示哪些内容:年,月,还有:以name名字相同的为一组,显示每组的数量


from dbo.Workcenter a -- 从哪个表里面

where year(a.CreateDate)=2017 -- 过滤:指定年份

group by year(a.CreateDate),month(a.CreateDate)

-- 需要进行分组的列

-- 将年相同分组以后,月再分组

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:sql 获取系统时间和表里面的时间列

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息