sqlÓαê
ÒòΪҪ¸ù¾ÝºÜ¸´ÔӵĹæÔò´¦ÀíÓû§Êý¾Ý£¬ËùÒÔÕâÀïÓõ½Êý¾Ý¿âµÄÓαꡣƽʱ²»ÔõôÓÃÕâ¸ö£¬Ð´ÔÚÕâÀï´¿´âΪ×Ô¼º±¸¸öÍü¡£
--½«Ñ§¼®ºÅÖØ¸´µÄ·ÅÈëÁÙʱ±í tmp_zdsoft_unitive_code(³ý¸ßÖÐѧ¶ÎÍâ)
drop table tmp_zdsoft_unitive_code;
select s.id ,sch.school_code,sch.school_name,s.student_name,s.unitive_code,s.identity_card,
c.section,c.acadyear,c.class_name ,s.now_state
INTO tmp_zdsoft_unitive_code
from student_info as s ,basic_schoolinfo as sch
,basic_class as c where s.unitive_code in(
select unitive_code from student_info where len(unitive_code)>0 and isdeleted='0' group by unitive_code having count(1)>1
) and c.section<>3 and s.isdeleted='0' and s.school_id=sch.id and s.class_id=c.id order by unitive_code,student_name
--½¨Á¢ÁÙʱ±í
drop table tmp_zdsoft_stuid;
create table tmp_zdsoft_stuid(id varchar(32) not null);
--ÀûÓÃÈý²ãÓα꣬¼ìË÷ѧ¼®ºÅÏàͬ£¬ÐÕÃûÉí·ÝÖ¤¶¼²»Í¬µÄѧÉú£¬´æ·Åµ½ÁÙʱ±ítmp_stuid
declare @unitive_code varchar(30),
@student_name varchar(60),
@identity_card varchar(18),
@stuid varchar(36)
--¼ìË÷ѧ¼®ºÅÖØ¸´µÄѧÉú---
declare tmp_cursor cursor for
select unitive_code,student_name,identity_card,id from tmp_zdsoft_unitive_code
OPEN tmp_cursor
FETCH next from tmp_cursor into @unitive_code,@student_name,@identity_card,@stuid
while @@fetch_status = 0
begin
begin
--------------ÄÚ²ãÑ»·£¨¼ìÑéÐÕÃûÔÚͬѧ¼®ºÅÊÇ·ñΨһ£©----------------------------
declare @count_name int
declare tmp_cursor2 cursor for
select count(1) from tmp_zdsoft_unitive_code
where unitive_code = @unitive_code and student_name=@student_name and (len(identity_card)=0 or isnull(identity_card,'')='')
OPEN tmp_cursor2
FETCH next from tmp_cursor2 into @count_name
while @@fetch_status = 0
begin
begin
if @count_name =1
begin
insert into tmp_zdsoft_stuid values(@s
Ïà¹ØÎĵµ£º
(1)char¡¢varchar¡¢textºÍnchar¡¢nvarchar¡¢ntext
charºÍvarcharµÄ³¤¶È¶¼ÔÚ1µ½8000Ö®¼ä£¬ËüÃǵÄÇø±ðÔÚÓÚcharÊǶ¨³¤×Ö·ûÊý¾Ý£¬¶øvarcharÊDZ䳤×Ö·ûÊý¾Ý¡£Ëùν¶¨³¤¾ÍÊdz¤¶È¹Ì¶¨µÄ£¬µ±ÊäÈëµÄÊý¾Ý³¤¶ÈûÓдﵽָ¶¨µÄ³¤¶Èʱ½«×Ô¶¯ÒÔÓ¢ÎĿոñÔÚÆäºóÃæÌî³ä£¬Ê¹³¤¶È´ïµ½ÏàÓ¦µÄ³¤¶È£»¶ø±ä³¤×Ö·ûÊý¾ÝÔò²»»áÒÔ¿Õ¸ñÌî³ä¡£text´æ´¢¿É±ä ......
select *
from (select row_number() over(partition by t.type order by date desc) rn,
t.*
from ±íÃû t)
where rn <= 2;
typeÒª·ÖµÄÀà
date ÅÅÐò ......
Ò»£¬PL/SQL¿éµÄ½á¹¹ºÍ×é³ÉÔªËØ
PL/SQL³ÌÐòÓÉÉùÃ÷²¿·Ö£¬Ö´Ðв¿·Ö£¬Òì³£´¦Àí²¿·ÖÈý¸ö²¿·Ö×é³É¡£½á¹¹ÈçÏ£º
DECLARE
/*ÉùÃ÷²¿·Ö£ºÔÚ´ËÉùÃ÷PL/SQL±äÁ¿£¬ÀàÐͼ°Óα꣬ÒÔ¼°¾Ö²¿µÄ´æ´¢¹ý³ÌºÍº¯Êý*/
BEGIN
/*Ö´Ðв¿·Ö£º¹ý³Ì¼°sqlÓï¾ä£¬³ÌÐòÖ÷Òª²¿·Ö£¬ÊDZØÐëµÄ*/
EXCEPTION
/*Òì³£´¦Àí²¿·Ö£º´íÎó´¦Àí*/
END
PL/SQL¿ ......
Êý¾Ý¿âÐÐתÁеÄsqlÓï¾ä
ÎÊÌâÃèÊö
¼ÙÉèÓÐÕÅѧÉú³É¼¨±í(CJ)ÈçÏÂ
Name Subject Result
ÕÅÈý ÓïÎÄ 80
ÕÅÈý Êýѧ 90
ÕÅÈý ÎïÀí 85
ÀîËÄ ÓïÎÄ 85
ÀîËÄ Êýѧ 92
ÀîËÄ ÎïÀí 82
ÏÖÔÚ Ïëд sql Óï¾ä ²éѯºó½á¹û Ϊ
ÐÕÃû ÓïÎÄ Êýѧ ÎïÀí
ÕÅÈý 80 90 85
ÀîËÄ 85 92 82& ......