Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

£¨×ª£©SQL¾­µäÃæÊÔÌ⼯£¨Èý£©


µÚ¶þÊ®Ì⣺
ÔõôÑù³éÈ¡ÖØ¸´¼Ç¼
񡜧
id name
--------
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
2 test2
3 test3
2 test2
6 test6
²é³öËùÓÐÓÐÖØ¸´¼Ç¼µÄÊý¾Ý£¬ÓÃÒ»¾äsql À´ÊµÏÖ
create table D(
id varchar (20),
name varchar (20)
)
insert into D values('1','test1')
insert into D values('2','test2')
insert into D values('3','test3')
insert into D values('4','test4')
insert into D values('6','test6')
insert into D values('5','test5')
insert into D values('2','test2')
insert into D values('3','test3')
insert into D values('4','test4')
insert into D values('7','test7')
insert into D values('4','test4')
insert into D values('6','test6')
insert into D values('5','test5')
insert into D values('2','test2')
insert into D values('3','test3')
insert into D values('4','test4')
insert into D values('8','test8')
insert into D values('10','test4')
select * from D where
--½â·¨Ò»:
--²éѯ³öÖØ¸´µÄ¼Ç¼
select id,name from D group by id,name having count(*)>1
--²éѯ³öÖØ¸´µÄ¼Ç¼¼°Öظ´´ÎÊý
select a.id,a.name from D a,(select id,name from D group by id,name having count(*)>1) b where a.id=b.id and a.name=b.name
--½â·¨¶þ:
select t1.* from D t1,
(select sum(1) as Sig,id,name from D group by id,name) as t2
where t1.name=t2.name and t1.id=t2.id and t2.Sig>1
µÚ¶þʮһÌ⣺
ÒÑÖªÔ­±í(t_salary)
year salary
2000 1000
2001 2000
2002 3000
2003 4000
ÏÈҪʵÏÖÏÔʾ½á¹û(salaryΪÒÔǰµÄ¹¤×ʺÍ)
year salary
2000 1000
2001 3000
ÇëÎÊSQLÓï¾äÔõôд?
create table t_salary(
year int,
salary int
)
select * from t_salary
insert into t_salary values(2000,1000)
insert into t_salary values(2001,2000)
insert into t_salary values(2002,3000)
insert into t_salary values(2003,4000)
--½â´ð£º
select year, (select sum(salary) from t_salary b where b.year <= a.year) salary from t_salary a group by year
µÚ¶þÊ®¶þÌ⣺
year month total
1996 1 3000
1996 3 4000
1996 7 5000
1997 3 4000
1997 6 3000
.
ÒªÇó°´ÈçϸñʽÊä³ö£º
year m1,m2,m3,m4
year ΪÄ꣬


Ïà¹ØÎĵµ£º

SQL»ù´¡:³£ÓÃSQLÓï¾äÏê½â

µ½½ñÌìΪֹ£¬ÈËÃǶԹØÏµÊý¾Ý¿â×öÁË´óÁ¿µÄÑо¿£¬²¢¿ª·¢³ö¹ØÏµÊý¾ÝÓïÑÔ£¬Îª²Ù×÷¹ØÏµÊý¾Ý¿âÌṩÁË·½±ãµÄÓû§½Ó¿Ú¡£¹ØÏµÊý¾ÝÓïÑÔĿǰÓм¸Ê®ÖÖ£¬¾ßÓÐÔö¼Ó¡¢É¾³ý¡¢Ð޸ġ¢²éѯ¡¢Êý¾Ý¶¨ÒåÓë¿ØÖÆµÈÍêÕûµÄÊý¾Ý¿â²Ù×÷¹¦ÄÜ¡£Í¨³£°ÑËüÃÇ·ÖΪÁ½Àࣺ¹ØÏµ´úÊýÀàºÍ¹ØÏµÑÝËãÀà¡£  
ÔÚÕâЩÓïÑÔÖУ¬½á¹¹»¯²éѯÓïÑÔSQLÒÔÆäÇ¿´óµÄÊý¾Ý¿â²Ù× ......

SQL ServerËÀËø×ܽá

1. ËÀËøÔ­Àí
    ¸ù¾Ý²Ù×÷ϵͳÖе͍Ò壺ËÀËøÊÇÖ¸ÔÚÒ»×é½ø³ÌÖеĸ÷¸ö½ø³Ì¾ùÕ¼Óв»»áÊͷŵÄ×ÊÔ´£¬µ«Òò»¥ÏàÉêÇë±»ÆäËû½ø³ÌËùÕ¾Óò»»áÊͷŵÄ×ÊÔ´¶ø´¦ÓÚµÄÒ»ÖÖÓÀ¾ÃµÈ´ý״̬¡£
    ËÀËøµÄËĸö±ØÒªÌõ¼þ£º
»¥³âÌõ¼þ(Mutual exclusion)£º×ÊÔ´²»Äܱ»¹²Ïí£¬Ö»ÄÜÓÉÒ»¸ö½ø³ÌʹÓá£
ÇëÇóÓë±£³ÖÌõ¼þ(Ho ......

sql Ö´ÐÐ˳Ðò

SQL SelectÓï¾äÍêÕûµÄÖ´ÐÐ˳Ðò
2009-06-02 15:57
SQL SelectÓï¾äÍêÕûµÄÖ´ÐÐ˳Ðò£º1¡¢from×Ó¾ä×é×°À´×Ô²»Í¬Êý¾ÝÔ´µÄÊý¾Ý£»2¡¢where×Ó¾ä»ùÓÚÖ¸¶¨µÄÌõ¼þ¶Ô¼Ç¼ÐнøÐÐɸѡ£»3¡¢group by×Ӿ佫Êý¾Ý»®·ÖΪ¶à¸ö·Ö×飻4¡¢Ê¹Óþۼ¯º¯Êý½øÐмÆË㣻5¡¢Ê¹ÓÃhaving×Ó¾äɸѡ·Ö×飻
ÒÔϽáÂÛÊÇͨ¹ýÔÚSql Server2000ÉϵÄʵÑéµÃ³öµÄ½áÂÛ£¬ ......

SQL SERVER 2005 .NET UDF

using System;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true,IsPrecise = true)]
public static bool RegExIsMatch(string pattern,string matchString)
{ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ