Õâ¸öSQL¸ÃÈçºÎд
дSQLÓï¾ä£º
±í1£ºCLASS
º¬ÓÐÁ½¸ö×ֶΣºID£¬CLASSNAME,±í½á¹¹ÈçÏ£º
ID CLASSNAME
1 A
2 B
3 C
4 D
±í2£ºSTUDENT
º¬ÓÐÈçÏÂ×ֶΣºSID£¬NAME£¬CLASSID
SIDÊÇÖ÷¼ü£¬CLASSIDÊÇÍâ¼ü£¬¿ÉÒÔͨ¹ýËüºÍCLASS±í×÷Á¬½Ó¡£
SID NAME CLASSID
01 Äã 1
02 ÎÒ 3
03 Ëû 4
........
ÒªÇóдһSQLÓï¾ä£¬²éѯ³öA£¬B£¬C£¬D°à¸÷ÓжàÉÙѧÉú¡£
SQL code:
select id,className,'ÈËÊý'=(select count(1) from student where classid=class.id) from class
SQL code:
SELECT SUM(sid), classid from student GROUP BY classid
²»ºÃÒâ˼£¬Ð´´íÁË£¬ÊÇcount(sid)
select c.classname,count(s.sid) from class c,student s where c.id=s.classid group by c.classname
SQL code:
select a.classname,b.fc
from (
select classid fcid,count(*) fc
from student
group by classid
) a
left join class b on a.fcid=b.id
SQL code
C
Ïà¹ØÎÊ´ð£º
´ó¼ÒºÃ£¬ÇëÎÊÔÚ±íMÖÐÓÐ×ֶΣºa b c d e
ÎÒÏë²é³öÆäÖÐÂú×ãÏÂÃæÈÎÒâÒ»ÏîµÄÊý¾Ý£¬1.×Ö¶Îa µÄÖµ²»ÊÇ ¡®Êé»ò±Ê»ò±¾¡¯ÖÐÈÎÒ»£¬2.aΪÊéµÄʱºò×Ö¶Îb,cÊÇ¿Õ;3.µ±aֵΪ±ÊµÄʱºòdÊÇ¿Õ;4.µ±aΪ±¾µÄʱºòb,d,e¶¼ÊÇ¿Õ;5.È ......
users±í
name companyId companyName
company±í
companyId companyName
1 a¹«Ë¾
2 b¹«Ë¾
......
ÓÐÁ½ÕÅ×Ö¶ÎÏàͬµÄ±íA£¬B¡£×Ö¶ÎΪSN, Name, Operator, Result, Remark
A±íÖÐ×Ö¶ÎSNΨһ£¬B±íÖÐ×Ö¶ÎSN²»Î¨Ò»£¬ÓкܶàÌõ
ÈçºÎÓÃÒ»ÌõselectÓï¾ä
°Ñ·ûºÏSN=¡¯abc¡¯µÄ¼Ç¼´ÓA£¬B±íÖÐɸѡ³öÀ´£¿
SQL co ......
sql server 2005 ´¥·¢Æ÷ Ö´ÐÐsp_executesql µÄÎÊÌâ
db1,db2ÊÇÒ»¸ö·þÎñÆ÷ server µÄ2¸öÊý¾Ý¿â
db1µÄtable1 ½¨Á¢Ò»¸öafter update´¥·¢Æ÷ ,µ± update table1 ºó½¨Á¢Ò»¸ö¸´ÖÆ±íµ½ db2µÄtabl ......
×Ö¶Îaa,¹²ÓÐ178¸öÊý¾Ý,ÏÔʾʱÊÇÒ»ÁÐÖ±ÅÅÏÂÀ´µÄ,ÎÒÏëÈÃÕâ178¸öÊý¾Ý,ÿÁÐÖ»ÏÔʾ5¸ö,¶àÁÐÏÔʾÍê,ÈçºÎʵÏÖ?
¼ÓÒ»¸öIDENTITYTÁÐ,°´ID%5À´·Ö
ÒýÓÃ
¼ÓÒ»¸öIDENTITYTÁÐ,°´ID%5À´·Ö
ID-1/5À´·Ö
SQL co ......