星座存貯過程

2021-04-21 18:38:44 字數 1713 閱讀 3640

use northwind

gocreate function getstar(@ datetime)

returns varchar(100)

asbegin

--僅一句 sql 搞定

return

(--declare @ datetime

--set @ = getdate()

select max(star)

from

(-- 星座,該星座開始日期所屬月,該星座開始日期所屬日

select '魔羯座' as star,1 as [month],1 as [day]

union all select '水瓶座',1,20

union all select '雙魚座',2,19

union all select '牧羊座',3,21

union all select '金牛座',4,20

union all select '雙子座',5,21

union all select '巨蟹座',6,22

union all select '獅子座',7,23

union all select '**座',8,23

union all select '天秤座',9,23

union all select '天蠍座',10,24

union all select '射手座',11,22

union all select '魔羯座',12,22

) stars

where dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))=(

select max(dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0))))

from

(select '魔羯座' as star,1 as [month],1 as [day]

union all select '水瓶座',1,20

union all select '雙魚座',2,19

union all select '牧羊座',3,21

union all select '金牛座',4,20

union all select '雙子座',5,21

union all select '巨蟹座',6,22

union all select '獅子座',7,23

union all select '**座',8,23

union all select '天秤座',9,23

union all select '天蠍座',10,24

union all select '射手座',11,22

union all select '魔羯座',12,22

) stars

where @ >= dateadd(day,[day]-1,dateadd(month,[month]-1,dateadd(year,datediff(year,0,@),0)))))

endgo

--測試

use northwind

select dbo.getstar(birthdate),count(*)

from employees

group by dbo.getstar(birthdate)

mysql 存貯過程 mysql存貯過程

first test,procedure 1 use testprocedure delimiter create procedure proce1 out par1 int begin select count into par1 from proce enddelimiter call proc...

存貯過程分頁

create procedure progetall sort varchar 10 公升序還是降序 fromtable varchar 20 哪乙個表 pageindex int,第幾行 pagesize int,每頁顯示多數行 pageby varchar 20 根據哪一字段排序 as begi...

分類 計算 挑選的存貯過程

create procedure xp lucky programe 1 username nvarchar 20 int big class int as 收藏總的節目總數 declare count program int select count program count from walk...