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
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......
--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 ......
Á¬½Ósql serverÊý¾Ý¿âÓõ½µÄÃüÃû¿Õ¼äÊÇusing System.Data.SqlClient;
Êý¾Ý¿âÁ¬½Ó´úÂë:¿ÉÒÔÔÚ´óÀàÖ®ÏÂÉùÃ÷ public SqlConnection myConnection; //sqlÁ¬½Ó¶ÔÏó
&nbs ......
SQL> select * from dept where deptno=&tt;
Enter value for tt:20
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
ÕâÑùÎÞÂÛÊäÈë¶àÉÙ´ÎttµÄÖµ£¬ÏµÍ³Ö»½¨Á¢Ò»¸öÖ´Ðмƻ®£¬Ì ......