ÇósqlÓï¾ä - Delphi / Êý¾Ý¿âÏà¹Ø
access±íÈçÏ£º
µØµã ÊýÁ¿ ÖÖÀà
a 2 ¼×
a 2 ÒÒ
b 2 ¼×
c 3 ¼×
c 3 ÒÒ
d 5 ¼×
d 3 ¼×
d 5 ÒÒ
e 1 ÒÒ
²éѯÓï¾ä1£ºSELECT µØµã,sum(ÊýÁ¿) from data group by µØµã
½á¹ûΪ£º
µØµã Expr1001
a 4
b 2
c 6
d 13
e 1
²éѯÓï¾ä2£ºSELECT µØµã,sum(ÊýÁ¿) from data where ÖÖÀà="¼×"group by µØµã
½á¹ûΪ£º
µØµã Expr1001
a 2
b 2
c 3
d 8
ÎÒÏëÒªµÄÊÇ£¬µ±²éѯÓï¾äÊÇ2µÄʱºò£¬µÃµ½ÈçϽá¹û£º
µØµã Expr1001
a 2
b 2
c 3
d 8
e 0
¾ÍÊÇ˵£ºµ±ÓÃÓï¾ä2µÄʱºò£¬µØµã×ֶεÄֵҪȫ²¿ÁгöÀ´£¬
Õâ¸öGroup BY ¿ÉÄÜÍêÔÚ²»ÁËÕâ¸ö¹¦ÄÜ£¬
×îºÃÔÙºÍËùÓеĵصã×Ö¶ÎJoinһϣ¬
SELECT * from ((SELECT DISTINCT µØµã from data) AS a LEFT JOIN (SELECT µØµã,sum(ÊýÁ¿) from data where ÖÖÀà="¼×"group by µØµã) as b ON a.µØµã=b.µØµã)
Óà having À´É¸Ñ¡
¿´´íÁË,Ä㻹ҪÏÔʾΪ0,ÄÇô¾ÍÓÃcaseÀ´´¦ÀíµÚ¶þÁÐ
SELECT µØµã,iif(sum(ÊýÁ¿),0,0,sum(ÊýÁ¿)) from data where ÖÖÀà="¼×"group by µØµã
IIf(expr, truepart, falsepart)
IIf º¯ÊýµÄÓï·¨°üº¬ÒÔϲÎÊý £¨²ÎÊý£ºÎª²Ù×÷¡¢Ê¼þ¡¢·½·¨¡¢ÊôÐÔ¡¢º¯Êý»ò¹ý³ÌÌṩÐÅÏ¢µÄÖµ¡££©
²ÎÊý ˵Ã÷
expr ±ØÑ¡¡£Òª¼ÆËãµÄ±í´ïʽ¡£
truepart ±ØÑ¡¡£expr Ϊ True ʱ·µ»ØµÄÖµ»ò±í´ïʽ¡£
falsepart ±ØÑ¡¡£expr Ϊ False ʱ·µ»ØµÄÖµ»ò±í´ïʽ¡£
˵Ã÷
ÓÉÓÚ IIf »á¼ÆËã tru
Ïà¹ØÎÊ´ð£º
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
¿ÉÄÜÒòΪ¹¤×÷µÄÔÒò ½Ó´¥Êý¾Ý¿âÕâ¿é±È½ÏÉÙ£¬Ö®Ç°¶¼ÊÇ×ö³ÌÐòÕâ¿é£¬Êý¾Ý¿âÕâ¿é¶¼ÓÐרÃŵÄÈËÀ´×ö ·Ö¹¤¶¼ºÜÃ÷ϸ ËùÒÔ¶ÔÊý¾Ý¿âÕâÒ»¿éÍêÈ«²»Á˽⡣ǰ¶Îʱ¼ä È¥ÃæÊÔÁ˼¸¼Ò¹«Ë¾ ¼¸ºõ¶¼ÊÇÔÚÊý¾Ý¿âÕâ¿é¹ÒµôµÄ Á¬¸ö¼òµ¥µÄSQ ......
1¡£ÔõÑùʹxp_cmdshellÄÜÍêÕûÊä³ö³¬¹ý255¸ö×Ö·ûµÄ×Ö·û´®¡£
2¡£select ʱ£¬¼ìË÷ËÙ¶ÈÊÇÓëfromºóµÄ TABLE˳ÐòÓйأ¬»¹ÊÇÓëwhereÌõ¼þµÄ˳ÐòÓйØ(TABLEÊý¾Ý¶àÉÙ )
ÔÚϵͳÊôÐÔÉ趨ÀïÓиöÑ¡Ïî,¿ÉÒÔÐ޸ĵ¥×Ö¶ÎÊä³ö×ÖÊýÏÞÖÆ. ......
ÓÐÕâÑùÒ»ÌõSQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
ÆäÖÐGet_Costtaxrate¡¢Get_Tcostvalue¶¼ÊǺ¯Êý£¬ÕâÁ½¸öº¯ÊýÀïÃ涼ÊDzéÕÒÒ»¸ö´ó±í£¬Get_Tcostvalue»¹ÐèÒªµ÷ÓÃGet_C ......