sqlÌæ»»Óï¾ä
--·Ö½â×Ö·û´®°üº¬µÄÐÅÏ¢ÖµºóÈ»ºóºÏ²¢µ½ÁíÍâÒ»±íµÄÐÅÏ¢
--(°®Ð¾õÂÞ.ع»ª(Ê®°ËÄê·çÓê,ÊصñùɽѩÁ«»¨¿ª) 2007-12-23 ¹ã¶«ÉîÛÚ)
/*ÎÊÌâÃèÊö
tba
ID classid name
1 1,2,3 Î÷·þ
2 2,3 ÖÐɽװ
3 1,3 Ãû¿ã
tbb
id classname
1 Ò·þ
2 ÉÏÒÂ
3 ¿ã×Ó
ÎҵõĽá¹ûÊÇ
id classname name
1 Ò·þ,ÉÏÒÂ,¿ã×Ó Î÷·þ
2 ÉÏÒ£¬¿ã×Ó ÖÐɽװ
3 Ò·þ£¬¿ã×Ó Ãû¿ã
*/
-----------------------------------------------------
--sql server 2000ÖеÄд·¨
create table tba(ID int,classid varchar(20),name varchar(10))
insert into tba values(1,'1,2,3','Î÷·þ')
insert into tba values(2,'2,3' ,'ÖÐɽװ')
insert into tba values(3,'1,3' ,'Ãû¿ã')
create table tbb(ID varchar(10), classname varchar(10))
insert into tbb values('1','Ò·þ')
insert into tbb values('2','ÉÏÒÂ')
insert into tbb values('3','¿ã×Ó')
go
--µÚ1ÖÖ·½·¨£¬´´½¨º¯ÊýÀ´ÏÔʾ
create function f_hb(@id varchar(10))
returns varchar(1000)
as
begin
declare @str varchar(1000)
set @str=''
select @str=@str+','+[classname] from tbb where charindex(','+cast(id as varchar)+',',','+@id+',')>0
return stuff(@str,1,1,'')
end
go
select id,classid=dbo.f_hb(classid),name from tba
drop function f_hb
/*
id classid name
----------- ------------- ----------
1 Ò·þ,ÉÏÒÂ,¿ã×Ó Î÷·þ
2 &
Ïà¹ØÎĵµ£º
ADO.net£¬Linq to SQLºÍEntity FrameworkÐÔÄÜʵ²â·ÖÎö
¡¡¡¡×î½üÎĵµÐ´Á˲»ÉÙ£¬µ¼ÖÂWordºÍExcelµÄʹÓÃÄÜÁ¦·ÉÒ»°ã³É³¤¡£¿¼Âǵ½ÏîÄ¿ÖжÁдÊý¾Ý¿âµÄ·½·¨´æÔÚЧÂʲ»¸ß£¬ÒÔÖÂÓ°ÏìÓû§ÌåÑéµÄÎÊÌ⣬¾ö¶¨²âÊÔÒ»ÏÂMicrosoftÐÂÍÆÐеÄLinqºÍEFÄܲ»ÄÜÔÚЧÂÊÉÏÓÐËù¸Ä½ø¡£
¡¡¡¡²âÊÔ»·¾³µ±È»¾ÍÊÇÎÒÕą̂±Ê¼Ç±¾ÁË£¬ÊÜÏÞÓëÓ²ÅÌתËÙ£¬ÔËÐÐÆð ......
¡¡¡¡Ä¿µÄ£º½«Êý¾ÝÅúÁ¿µ¼ÈëÔ¶³Ì·þÎñÆ÷
¡¡¡¡»·¾³£ºSQLÈí¼þ£¬EXCELÈí¼þ£¬VS2005Èí¼þ£¬±¾µØÁ½¸ö»úÆ÷É϶¼ÓÐSQLÊý¾Ý¿â£¬¶øÇÒÊý¾Ý´æ·ÅÔÚÆäÖÐÒ»¸ö±í¡£
¡¡¡¡²Ù×÷ʵ¼ù
¡¡¡¡1¡¢ÓÃÔ¶³ÌÊý¾Ý¿âµÄip¡¢Óû§Ãû¡¢ÃÜÂëÔÚ±¾µØµÇ¼£»
¡¡¡¡2¡¢½á¹û£¬ÆäÖÐÒ»¸ö»úÆ÷ÄܵǼ£¬Ò»¸ö²»ÄܵǼ£¨ÒÔϲÙ×÷ÔڿɵǼµÄ»úÆ÷ÉÏÍê³É£©£»
¡¡¡¡3¡¢µÚÒ»´ÎÎÒÏëͨ ......
1. GROUP BY ÊÇ·Ö×é²éѯ, Ò»°ã GROUP BY ÊǺ;ۺϺ¯ÊýÅäºÏʹÓÃ
group by ÓÐÒ»¸öÔÔò,¾ÍÊÇ select ºóÃæµÄËùÓÐÁÐÖÐ,ûÓÐʹÓþۺϺ¯ÊýµÄÁÐ,±ØÐë³öÏÖÔÚ group by ºóÃ棨ÖØÒª£©
ÀýÈç,ÓÐÈçÏÂÊý¾Ý¿â±í£º
A B
1 abc
1 bcd
1 asdfg
Èç¹ûÓÐÈ ......
ÉùÃ÷×Ö¶ÎÓ³Éä
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FiledRef
{
String fieldName();
}
ÉùÃ÷±íÓ³Éä
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TableRef
{
& ......