作者hasio227 (阿进)
看板Database
标题Re: [SQL ] select 资料表中每月月初及月底的资料( …
时间Wed Nov 19 21:08:41 2008
(....前面恕删)
小弟没事情做,用MS-SQL写了一下,如果大大您不是使用MS-SQL的话你可能要改一下
语法才可以用喔︿︿
create table #test (日期 char(8),交易 int)
insert into #test values('20080130',20)
insert into #test values('20080105',100)
insert into #test values('20080103',5)
insert into #test values('20021031',45)
insert into #test values('20021008',32)
insert into #test values('20021001',86)
insert into #test values('20020203',30)
insert into #test values('20020201',65)
go
select *
from #test t1
where substring(日期,7,8) =
(
select max(substring(日期,7,8))
from #test t2
where substring(t1.日期,5,2)=substring(t2.日期,5,2)
)
or substring(日期,7,8) =
(
select min(substring(日期,7,8))
from #test t2
where substring(t1.日期,5,2)=substring(t2.日期,5,2)
)
go
drop table #test
另外....
您不是要收寻月初和月底的资料吗?
20080130 20
20080103 5
20021031 45
20021008 32 <------10月的月初资料大大您给的好像是20021001
所以应该不是10月八号才对
20020203 30
20020201 65
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.127.194.122