SQLÏ°Ìâ2
µÚʮһÌ⣺
Óбístudents(name,class,grade),ÇëÓñê×¼sqlÓï¾äÍê³É
name class grade
ÕÅÈý Êýѧ 81
ÀîËÄ ÓïÎÄ 70
ÍõÎå Êýѧ 90
ÕÅÈý ÓïÎÄ 60
ÀîËÄ Êýѧ 100
ÍõÎå ÓïÎÄ 90
ÍõÎå Ó¢Óï 81
ÒªÇó: ÓÃsqlÓï¾äÊä³ö¸÷ÃŹ¦¿Î¶¼´óÓÚ80·ÖµÄͬѧÐÕÃû?
create table students (
name varchar(25),
class varchar(25),
grade int
)
insert into students values ('ÕÅÈý','ÓïÎÄ',20)
insert into students values ('ÕÅÈý','Êýѧ',90)
insert into students values ('ÕÅÈý','Ó¢Óï',50)
insert into students values ('ÀîËÄ','ÓïÎÄ',81)
insert into students values ('ÀîËÄ','Êýѧ',60)
insert into students values ('ÀîËÄ','Ó¢Óï',90)
insert into students values ('Íõ¶þ','Êýѧ',81)
insert into students values ('Íõ¶þ','Ó¢Óï',90)
insert into students values ('ÀîÎå','Êýѧ',83)
insert into students values ('ÀîÎå','Ó¢Óï',90)
insert into students values ('ÀîÎå','»¯Ñ§',90)
---Ñ¡³öËùÓгɼ¨´óÓÚ80·ÖµÄѧÉúÐÕÃû-----
------½â·¨Ò»------
select name from students group by name having min(grade)>80
------½â·¨¶þ------
select distinct Name from students where grade >80 and Name not in (select Name from students where grade <80)
------½â·¨Èý------
select distinct name from students where name not in (select name from students where grade <=80 group by name )
-----½â·¨ËÄ-------
select name from students group by name having name not in (select name from students where grade<=80)
µÚÊ®¶þÌ⣺
ÒÑÖªÒ»¸ö±íµÄ½á¹¹Îª£º
ÐÕÃû ¿ÆÄ¿ ³É¼¨
ÕÅÈý ÓïÎÄ 20
ÕÅÈý Êýѧ 30
ÕÅÈý Ó¢Óï 50
ÀîËÄ ÓïÎÄ 70
ÀîËÄ Êýѧ 60
ÀîËÄ Ó¢Óï 90
ÔõÑùͨ¹ýselectÓï¾ä°ÑËû±ä³ÉÒÔϽṹ£º
ÐÕÃû ÓïÎÄ Êýѧ Ó¢Óï
ÕÅÈý 20 30 50
ÀîËÄ 70 60 90
create table students (
name varchar(25),
class varchar(25),
grade int
)
insert into students values ('ÕÅÈý','ÓïÎÄ',20)
insert into students values ('ÕÅÈý','Êýѧ',90)
insert into students values ('ÕÅÈý','Ó¢Óï',50)
insert into students values ('ÀîËÄ','ÓïÎÄ',81)
insert into students values ('ÀîËÄ','Êýѧ',60)
insert into students values ('ÀîËÄ','Ó¢Óï',90)
--½â´ð£º
select A.Name,A.grade as ÓïÎÄ,
Ïà¹ØÎĵµ£º
µÚÒ»½Ú¡¢SQL×¢ÈëµÄÒ»°ã²½Öè
Ê×ÏÈ£¬Åжϻ·¾³£¬Ñ°ÕÒ×¢Èëµã£¬ÅжÏÊý¾Ý¿âÀàÐÍ£¬ÕâÔÚÈëÃÅƪÒѾ½²¹ýÁË¡£
Æä´Î£¬¸ù¾Ý×¢Èë²ÎÊýÀàÐÍ£¬ÔÚÄÔº£ÖÐÖع¹SQLÓï¾äµÄÔò£¬°´²ÎÊýÀàÐÍÖ÷Òª·ÖΪÏÂÃæÈýÖÖ£º
(A) ID=49 ÕâÀà×¢ÈëµÄ²ÎÊýÊÇÊý×ÖÐÍ£¬SQLÓï¾äÔò´óÖÂÈçÏ£º
Select * from ±íÃû where ×Ö¶Î=49
×¢ÈëµÄ²ÎÊýΪID=49 And [²é ......
ÔÎÄ´«ËÍÃÅ£ºhttp://topic.csdn.net/u/20091119/17/388cd1dd-4018-403f-a97f-0bc135895264.html?85256
Êý¾Ý¿âÀýÈç:
id ÐÕ Ãû ½± ½ð
1 ÕÅÈý 20Íò
2 ÀîËÄ 10Íò
3   ......
MySQLÌṩ±ê×¼µÄSQLģʽƥÅ䣬ÒÔ¼°Ò»ÖÖ»ùÓÚÏóUnixʵÓóÌÐòÈçvi¡¢grepºÍsedµÄÀ©Õ¹ÕýÔò±í´ïʽģʽƥÅäµÄ¸ñʽ¡£ ±ê×¼µÄSQLģʽƥÅä
SQLµÄģʽƥÅäÔÊÐíÄãʹÓÓ_”Æ¥ÅäÈκε¥¸ö×Ö·û£¬¶ø“%”Æ¥ÅäÈÎÒâÊýÄ¿×Ö·û(°üÀ¨Áã¸ö×Ö·û)¡£ÔÚ MySQLÖУ¬SQLµÄģʽȱʡÊǺöÂÔ´óСдµÄ¡£ÏÂÃæÏÔʾһЩÀý×Ó¡£×¢ÒâÔÚÄãÊ ......
¿ª·¢Êý¾Ý¿âÓ¦Óã¬Ñ¡ÔñÒ»¸öºÃµÄÊý¾Ý¿âÊǷdz£ÖØÒªµÄ¡£±¾ÎÄ´ÓһЩ·½Ãæ±È½ÏÁËSQL ServerÓëOracle¡¢DB2ÈýÖÖÊý¾Ý¿â£¬ÎªÄãÑ¡ÔñÊý¾Ý¿âÌṩһЩ²Î¿¼¡£
¡¡¡¡
¡¡¡¡¿ª·ÅÐÔ
¡¡¡¡SQL Server
¡¡¡¡Ö»ÄÜÔÚWindows ÉÏÔËÐУ¬Ã»ÓÐË¿ºÁµÄ¿ª·ÅÐÔ£¬²Ù×÷ϵͳµÄϵͳµÄÎȶ¨¶ÔÊý¾Ý¿âÊÇÊ®·ÖÖØÒªµÄ¡£Windows9XϵÁвúÆ·ÊÇÆ«ÖØÓÚ×ÀÃæÓ¦Óã¬NT se ......
µÚÒ»Ì⣺
Ϊ¹ÜÀíÒµÎñÅàѵÐÅÏ¢£¬½¨Á¢3¸ö±í£º
S(S#,SN,SD,SA)S#,SN,SD,SA·Ö±ð´ú±íѧºÅ£¬Ñ§Ô±ÐÕÃû£¬ËùÊôµ¥Î»£¬Ñ§Ô±ÄêÁä
C(C#,CN)C#,CN·Ö±ð´ú±í¿Î³Ì±àºÅ£¬¿Î³ÌÃû³Æ
SC(S#,C#,G) S#,C#,G·Ö±ð´ú±íѧºÅ£¬ËùÑ¡µÄ¿Î³Ì±àºÅ£¬Ñ§Ï°³É¼¨
(1)ʹÓñê×¼SQLǶÌ×Óï¾ä²éѯѡÐ޿γÌÃû³ÆΪ’Ë°ÊÕ»ù´¡’µÄѧԱѧºÅºÍÐÕÃû?
(2) ʹ ......