刚刚学习Sybase,很多都不明白,想实现这样一个功能: [color=#FF0000]数据库DB_TJ中有一张表T_YG_RZSJFZ(员工入职时间分布),要
刚刚学习Sybase,很多都不明白,想实现这样一个功能:
数据库DB_TJ中有一张表T_YG_RZSJFZ(员工入职时间分布),要求分别按年份、月份统计出员工的入职情况分布情况,如各年份入职员工数量、各月份入职员工数量、某年某月入职员工数量。
请建立T_YG_RZSJFZ,编写SQL,把T_YGTXL中上述统计信息插入T_YG_RZSJFZ。
sql如下:
declare @p_rzrq char(10)
declare @count80 int
declare @count81 int
declare @count82 int
declare @count87 int
/*declare the cursor*/
declare p_cursor cursor for
select datepart(yy,rzrq) from T_YGTXL
open p_cursor
fetch p_cursor into @p_rzrq,@count80,@count81,@count82,@count87
while(@@sqlstatus=0)
if(@ p_rzrq=1980) @count80=@count80+1
elsif (@ p_rzrq=1981) @count81=@count81+1
elsif (@ p_rzrq=1987) @count87=@count87+1
else @count82=@count82+1
insert into T_YG_RZSJFZ(time,countpeople)values('1980',count80)
insert into T_YG_RZSJFZ(time,countpeople)values('1981',count81)
insert into T_YG_RZSJFZ(time,countpeople)values('1982',count82)
insert into T_YG_RZSJFZ(time,countpeople)values('1987',count87)
fetch p_cursor into @p_rzrq
close p_cursor
deallocate cursor p_cursor
老是提示DECLARE CURSOR must be the only statement in a query batch. 请大侠们指导啊。急求