ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

³£ÓÃSQLÓï¾äÊÕ²Ø<Ò»)
2015-11-21 01:40:27 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:0´Î
Tags£º³£Óà SQL Óï¾ä ÊÕ²Ø <

MSSQL ²éѯ

select * from class;²éѯ±íclassÖеÄËùÓÐÁÐ.

select * from class; ²éѯ±íclassÖеÄËùÓÐÁÐ.
select class,teacher from class;²éѯ±íclassÖеÄÁÐclass,teacher
Select count(*) as count_all from class;·µ»Ø±íclassÖеÄ×ÜÐÐÊý¸ø½á¹û¼¯.
select sum(studentnumber) as all_student_number from class :·µ»Øclass±íÖÐstudentnumberµÄ×ÜÊý¸ø½á¹û¼¯
select avg(studentnumber) as avg_student_number  from class :·µ»ØclassÖÐstudentnumberµÄƽ¾ùÖµ¸ø½á¹û¼¯
Select max(studentnumber)  as max_studentnumber from class :Çóij¸ö×ֶεÄ×î´óÖµ,×îСֵ.minÊÇ×îСֵ.
select * from class where studentnumber=(Select max(studentnumber) from class):ÇóµÄ×î´óÖµ¿ÉÒÔ×÷ΪÌõ¼þ±»ÒýÓÃ.
Select * from class where studentnumber=50(>50,>=50,<50,<=50,<>50):·µ»Østudentnumber=50 (>50,>=50,<50,<=50,²»µÈÓÚ50):µÄ¼Ç¼
Select * from class where studentnumber<>50 and teacher='li¡® Á½¸ö²éѯÌõ¼þÓÃand±íʾÓë,or±íʾ»ò.
Select * from class where studentnumber in (44,55) : in±íʾstudentnumberΪÀ¨ºÅÖÐËùÁеĿÉÄÜÖµ.
Select * from class where class in (select class from student) :inÖеÄÄÚÈÝ¿ÉÒÔÊÇÁíÒ»¸ö²éѯÓï¾äµÄ½á¹û.
Select distinct class from student :²éѯ×ֶεÄÖµ²»Öظ´
select * from class order by studentnumber (asc,desc) :¶Ô²éѯ½á¹ûÅÅÐò,¿ÉÒÔ°´ÉýÐò,Ò²¿ÉÒÔ°´½µÐò.

ÐøÒ»

select class,count(*) from student group by class :²éѯ½á¹û¸ù¾Ýgroup by ·Ö×é.
select class,count(*) from student group by class having count(*)=5 :¶Ô·Ö×éµÄ½á¹ûÔÙÓÃÌõ¼þ¹ýÂË
select * from student where id<2
UNION (ALL)
select * from student where age>19 :UNION:½«Á½¸ö²éѯÓï¾äµÄ²éѯ½á¹û·ÅÔÚÒ»Æð,Èç¹ûÓÐÖØ¸´µÄÐÐ,
¾Íɾ³ý,Èç¹ûÊÇUNION ALL:ÔòÖØ¸´µÄÐв»É¾³ý.
Ä£ºýÆ¥Åä²éѯ: select * from student where name like '%ang%'
ÕûÐÍ,ÈÕÆÚÀàÐ͵Ä×ֶοÉÒÔÖ¸¶¨·¶Î§.ÓÃbetween
select * from student where born between '1980-05-04' and '2983-10-18'
select * ,12 from student ·µ»Ø½á¹ûÖÐÔö¼ÓÒ»ÁÐ,ÇÒÖµ¾ùΪ12.
select RTRIM(class)+RTRIM(teacher) AS name1,studentnumber from class :½«Á½¸ö×Ö¶ÎÏÈɾ³ýβ²¿µÄ¿Õ¸ñ,ÔÙÁ¬½ÓÆðÀ´·µ»Ø. ÆäÖÐ:Á¬½ÓÆðÀ´µÄ×Ö¶ÎÃû³Æ·µ»ØÊ±Îªname1
Select class.*,student.* from class,student where class.class=student.class :Á½¸ö±íµÄÄÚÈÝÁªºÏÆðÀ´²éѯ,×Ö¶Î
Ò²¿ÉÒÔÓÃJOIN×Ó¾äʵÏÖ:select * from class JOIN student on class.class=student.class
JOINÓÖ·ÖΪÄÚÁ¬½Ó,ÍâÁ¬½Ó,×óÍâÁ¬½Ó,ÓÒÍâÁ¬½ÓµÈ,¾ßÌåÇë²é¿´Ïà¹ØµÄÊý¾Ý¿âµÄÊÖ²á.

Ôöɾ¸Ä²Ù×÷

²åÈë:
Ö¸¶¨×Ö¶ÎÃû³Æ¼°ÖµµÄ²åÈë
Insert into class (class,studentnumber,teacher) values('gaoer',55,'abc');
²»Ö¸¶¨×Ö¶ÎÃû³ÆµÄ²åÈëInsert into class values('chuyi','abc',55);
Ò»´Î²åÈë¶àÌõ¼Ç¼:Ö»ÄÜÖ´ÐжàÌõinsertÓï¾ä.
´ÓÁíÒ»¸ö±íÖжÁ³öÊý¾Ý²åÈ뵱ǰµÄ±íÏÈ´´½¨Ò»¸öбí:select * into class_bak from class where 1=2
insert into class_bak select * from class where class='gaoer¡®
ÐÞ¸Ä:Update class set class='gaoerer' where class='gaoer¡®
ɾ³ý:Delete from class where class='gaoerer'
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºÊý¾Ý¿âSQLServer2012±Ê¼Ç£¨¶þ£©¨.. ÏÂһƪ£ºSqlServerÓëMySQL»ù±¾²Ù×÷Óï¾ä¶Ô±È

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ: