|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
为多种编程语言提供了API。这些编程语言包括C、C++、Python、Java、Perl、PHP、Eiffel、Ruby和Tcl等。函数
usenorthwind
go
CREATEFUNCTIONGetStar(@datetime)
RETURNSvarchar(100)
AS
BEGIN
--仅一句SQL弄定
RETURN
(
--declare@datetime
--set@=getdate()
selectmax(star)
from
(
--星座,该星座入手下手日期所属月,该星座入手下手日期所属日
select魔羯座asstar,1as[month],1as[day]
unionallselect水瓶座,1,20
unionallselect双鱼座,2,19
unionallselect牧羊座,3,21
unionallselect金牛座,4,20
unionallselect双子座,5,21
unionallselect巨蟹座,6,22
unionallselect狮子座,7,23
unionallselect童贞座,8,23
unionallselect天秤座,9,23
unionallselect天蝎座,10,24
unionallselect弓手座,11,22
unionallselect魔羯座,12,22
)stars
wheredateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))
=
(
selectmax(dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0))))
from
(
select魔羯座asstar,1as[month],1as[day]
unionallselect水瓶座,1,20
unionallselect双鱼座,2,19
unionallselect牧羊座,3,21
unionallselect金牛座,4,20
unionallselect双子座,5,21
unionallselect巨蟹座,6,22
unionallselect狮子座,7,23
unionallselect童贞座,8,23
unionallselect天秤座,9,23
unionallselect天蝎座,10,24
unionallselect弓手座,11,22
unionallselect魔羯座,12,22
)stars
where@>=dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))
)
)
end
go
--测试
usenorthwind
selectdbo.getstar(birthdate),count(*)
fromemployees
groupbydbo.getstar(birthdate)
对于update操作,只需要把event中的旧行和新行值对调即可。 |
|