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

sql·Ö×é²éѯÎÊÌâ

Çé¾°Ò»£º
±íÖÐÊý¾Ý
name  score
 aaa   11
 aaa   19
 bbb   12
 bbb   18
 ccc   19
 ddd   21
ÆÚÍû²éѯ½á¹ûÈçÏÂ
name   score
 aaa     30
 bbb     30
 ccc      19
 ddd     21
Sql´úÂë
---¼ì²é±íÊÇ·ñ´æÔÚ   
if exists(select * from sysobjects where name='testSum')   
drop table testSum   
go   
---´´½¨±í   
create table testSum   
(   
   tid int primary key identity(1,1),   
   tname varchar(30) null,   
   tscor int null  
)   
go   
insert into testSum (tname,tscor)    
select 'aaa',11   
union all    
select 'aaa',19   
union all    
select 'bbb',12   
union all  
select 'bbb',18   
union all  
select 'ccc',19   
union all    
select 'ddd',21   
---²éѯÓï¾ä   
select tname ,sum(tscor) from testSum group by tname   
  
---Ö»²éѯtscor×ܺÍΪ30µÄ   
 select tname ,sum(tscor) from testSum group by tname having sum(tscor)=30  
---¼ì²é±íÊÇ·ñ´æÔÚ
if exists(select * from sysobjects where name='testSum')
drop table testSum
go
---´´½¨±í
create table testSum
(
tid int primary key identity(1,1),
tname varchar(30) null,
tscor int null
)
go
insert into testSum (tname,tscor)
select 'aaa',11
union all
select 'aaa',19
union


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......

SQL ËÙ²éÊÖ²á

--SQL ËÙ²éÊÖ²á
/*******************************************/
SELECT
--ÓÃ;£º´ÓÖ¸¶¨±íÖÐÈ¡³öÖ¸¶¨ÁеÄÊý¾Ý
--Óï·¨£º
SELECT column_name(s) from table_name
--Ö÷Òª×Ö¾ä¿ÉժҪΪ:
SELECT select_list [INTO new_table]
from table_source
[WHERE search_condition]
[GROUP BY group_by_expression]
[HAVING s ......

C#Êý¾Ý¿â±à³Ì»ù´¡Ö®sqlÓï¾ä²Ù×÷Êý¾Ý¿âÊý¾Ý

        Á¬½Ósql serverÊý¾Ý¿âÓõ½µÄÃüÃû¿Õ¼äÊÇusing System.Data.SqlClient;
  Êý¾Ý¿âÁ¬½Ó´úÂë:¿ÉÒÔÔÚ´óÀàÖ®ÏÂÉùÃ÷ public SqlConnection myConnection;  //sqlÁ¬½Ó¶ÔÏó
               &nbs ......

ÓÃÌæ´ú±äÁ¿µÄ·½Ê½±àдsqlÓï¾ä

SQL> select * from dept where deptno=&tt;
Enter value for tt:20
DEPTNO DNAME          LOC
------ -------------- -------------
    10 ACCOUNTING     NEW YORK
ÕâÑùÎÞÂÛÊäÈë¶àÉÙ´ÎttµÄÖµ£¬ÏµÍ³Ö»½¨Á¢Ò»¸öÖ´Ðмƻ®£¬Ì ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ