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

SQL_ѧÉú

 
µÚÒ»²¿·Ö
µ¥±í²éѯ
ÀýÒ»£º²éѯȫÌåѧÉúµÄѧºÅÓëÐÕÃû
SELECT Sno,Sname
from Student;
Àý¶þ£º²éѯȫÌåѧÉúµÄÐÕÃû¡¢Ñ§ºÅ¡¢ËùÔÚϵ
SELECT Sname,Sno,Sdept
from Student;
ÀýÈý£º²éѯȫÌåѧÉúµÄÏêϸ¼Ç¼
SELECT *
from Student;
µÈ¼ÛÓÚ£º
SELECT *
from Student;
ÀýËÄ£º²éѯȫÌåѧÉúµÄÐÕÃû¼°Æä³öÉúÄê·Ý
SELECT Sname,2009-Sage
from Student;
ÀýÎ壺²éѯȫÌåѧÉúµÄÐÕÃû¡¢³öÉúÄê·ÝºÍËùÔÚµÄԺϵ£¬ÒªÇóÓÃСд×Öĸ±íʾËùÓеÄϵÃû
SELECT Sname,'Year of Birth:',2004-Sage,LOWER(Sdept)
from Student;
Ö¸¶¨ÁбðÃûÈçÏ·½·¨£º
SELECT Sname NAME,'Year of Birth:' BIRTH,2009-Sage BIRTHDAY,
LOWER(Sdept) DEPARTMENT
from Student;
ÀýÁù£º²éѯѡÐÞÁ˿γ̵ÄѧÉúµÄѧºÅ
SELECT Sno //µÈ¼ÛÓÚSELECT ALL Sno
from SC;
È¥µôÖظ´Ðз½·¨£º
SELECT DISTINCT Sno
from SC;
ÀýÆߣº²éѯ¼ÆËã»ú¿ÆѧϵȫÌåѧÉúµÄÃûµ¥
SELECT Sname
from Student
WHERE Sdept='CS';
Àý°Ë£º²éѯËùÓÐÄêÁäÔÚ20ËêÒÔϵÄѧÉúµÄÐÕÃû¼°ÆäÄêÁä
SELECT Sname,Sage
from Student
WHERE Sage<20;
Àý¾Å£º²éѯ¿¼ÊԳɼ¨Óв»¼°¸ñµÄѧÉúµÄѧºÅ
SELECT DISTINCT Sno
from SC
WHERE Grade<60;
ÀýÊ®£º²éѯÄêÁäÔÚ20-23Ëê(°üÀ¨20ËêºÍ23Ëê)Ö®¼äµÄѧÉúµÄÐÕÃû¡¢Ïµ±ðºÍÄêÁä
SELECT Sname,Sdept,Sage
from Student
WHERE Sage BETWEEN 20 AND 23;
Àýʮһ£º²éѯÄêÁä²»ÔÚ20-23ËêÖ®¼äµÄѧÉúµÄÐÕÃû¡¢Ïµ±ð¡¢ºÍÄêÁä
SELECT Sname,Sdept,Sage
from Student
WHERE Sage NOT BETWEEN 20 AND 23;
ÀýÊ®¶þ£º²éѯ¼ÆËã»ú¿Æѧϵ(CS)¡¢Êýѧϵ(MA)ºÍÐÅϢϵ(IS)ѧÉúµÄÐÕÃûºÍÐÔ±ð
SELECT Sname,Ssex
from Student
WHERE Sdept IN('CS','MA','IS');
µÈ¼ÛÓÚ£º
SELECT Sname,Ssex
from Student
WHERE Sdept='CS'OR Sdept='MA' OR Sdept='IS';
ÀýÊ®Èý£º²éѯ¼È²»ÊǼÆËã»ú¿Æѧϵ¡¢Êýѧϵ£¬Ò²²»ÊÇÐÅϢϵµÄÐÕÃûºÍÐÔ±ð
SELECT Sname,Ssex
from Student
WHERE Sdept NOT IN('IS','MA','CS');
ÀýÊ®ËÄ£º²éѯѧºÅΪ200215121µÄѧÉúµÄÏêϸÇé¿ö
SELECT *
from Student
WHERE Sno LIKE '200215126 ';//ÊäÈëÊý×Ö6ºó¿ÕÒ»¸ñºóÊäÈëµ¥ÒýºÅ£¬·ñÔò²éѯ²»ÏÔʾ
µÈ¼ÛÓÚ£º
SELECT *
from Student
WHERE Sno='200215121';
ÀýÊ®Î壺²éѯËùÓÐÐÕÁõµÄѧÉúµÄÐÕÃû¡¢Ñ§ºÅºÍÐÔ±ð
SELECT Sname,Sno,Ssex
from Student
WHERE Sname LIKE 'Íõ%';
ÀýÊ®Áù£º²éѯÐՔŷÑô”ÇÒÈ«ÃûÎ


Ïà¹ØÎĵµ£º

sql È¡·´

 update anketo1 set fb = substring('10',fb+1,1) WHERE id =5
ºóÀ´ÎÊÁËBM,BM˵ֱ½ÓÈ¡·´
update anketo1 set fb = ~ fb WHERE id =5
ÎÒ¸æËßÁËBMÓÃsubstringÒ²¿ÉÒÔ.
BM˵:"Õâ¼Ò»ïÀ÷º¦£¬ÕâÒ²ÄÜÏë³ö,ÕâÊôÓÚаÃÅÎ书."
×îºóÓÖÏëµ½ÓÃABSÈ¡¾ø¶ÔÖµÒ²¿ÉÒÔ
update anketo1 set fb = abs(fb-1)
ÎÒ¾õµÃ²»¹ÜÊÇʲôÎ书,ÄÜÖ ......

Ö´ÐÐSQLÈ¡PostgreSQLÊý¾Ý¿â»ò±í´óС

ÔÚPostgreSQL8.1.3ÉÏ¿ÉÒÔwork
1. È¡Êý¾Ý¿â´óС
SELECT pg_size_pretty(pg_database_size('somedatabase')) As fulldbsize
2. È¡±í´óС
SELECT pg_size_pretty(pg_total_relation_size('someschema.sometable')) As fulltblsize, pg_size_pretty(pg_relation_size('someschema.sometable')) As justthetblsize
Ô­Ìù£º
......

SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö

 SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö
1¡¢ÔÚSQL SERVERÀï²éѯExcelÊý¾Ý:
-- ======================================================
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
ÏÂÃæÊǸö²éÑ ......

PB Êý¾Ý¿âÁ¬½ÓÒÔ¼°sqlÓï¾äÔËÐÐÐÅÏ¢·µ»Ø´úÂë½âÊÍ´óÈ«


Èç¹ûÒ»¸ö SQL Óï¾ä·¢ÉúÁË´íÎó£¬ÄÇô sqlca.sqlcode ½«ÊÇ·ÇÁãÖµ¡£
Èç¹û sqlca.sqlcode СÓÚ 0 ÄÇô¾ÍÊÇ·¢ÉúÁËijÖÖÑÏÖصĴíÎó£¬ÏóÊý¾Ý¿â¶¨ÒåÓë²éѯ¶¨Òå²»Ò»Öµȣ®
Èç¹û´óÓÚ 0 ÔòÊÇͨ³£µÄ´íÎó£¬Ïó±í²»°üÀ¨ËùÒªÇóµÄÐеȣ®
sqlca.sqlcode == 0£¬³É¹¦
sqlca.sqlcode == -1 ʧ°Ü     £¨»ñÈ¡¾ßÌåʧ°ÜÐÅÏ¢ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ