22,209
社区成员
发帖
与我相关
我的任务
分享
-- 都去过节了
create table test(a int, b int, c varchar(10), d varchar(10))
go
insert into test values
(1, 123, '2016-07-03', '生产'),
(2, 123, '2016-05-01', '生产'),
(3, 123, '2015-07-01', '生产'),
(4, 123, '2016-07-02', '生产')
go
select * from test
go
select b,
d,
left(c,4) ,
case when substring(c,6,2) >= '06' then '前半年' else '后半年' end
from test
group by b,d,left(c,4),
case when substring(c,6,2) >= '06' then '前半年' else '后半年' end
go
drop table test
go
(4 行受影响)
a b c d
----------- ----------- ---------- ----------
1 123 2016-07-03 生产
2 123 2016-05-01 生产
3 123 2015-07-01 生产
4 123 2016-07-02 生产
(4 行受影响)
b d
----------- ---------- -------- ------
123 生产 2015 前半年
123 生产 2016 后半年
123 生产 2016 前半年
(3 行受影响)