×ðÁú¿­Ê±¹ÙÍøµÇ¼

sqlÖÐsumµÄÓ÷¨½â˵

sql ÖÐµÄ sum º¯ÊýÓÃÓÚÅÌËãÒ»×éÖµµÄ×ܺÍ£¬Ó﷨Ϊ sum(expression)¡£Ëüͨ³£Óë where ×Ó¾äÍŽáʹÓã¬ÒÔ¶ÔÌض¨Ìõ¼þϵÄÖµ¾ÙÐÐÇóºÍ¡£sum º¯Êý¿ÉÒÔÓë distinct Òªº¦×ÖÍŽáʹÓã¬ÒÔ¶ÔΨһֵ¾ÙÐÐÇóºÍ£¬Ò²¿ÉÒÔÓë group by ×Ó¾äÍŽáʹÓã¬ÒÔ¶Ô·Ö×éºóµÄÊý¾Ý¾ÙÐÐÇóºÍ¡£

SQL ÖÐ SUM º¯Êý

SUM º¯ÊýÊÇ SQL Öг£ÓõľۺϺ¯Êý£¬ÓÃÓÚÅÌËãÒ»×éÖµµÄ×ܺÍ¡£Ëüͨ³£ÓÃÓÚͳ¼ÆÆÊÎöºÍÊý¾Ý»ã×Ü¡£

Óï·¨

SUM(expression)

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬expression ÊÇÒªÅÌËã×ܺ͵ÄÁлò±í´ïʽ¡£

ʾÀý

ÒÔÏÂÅÌÎÊÅÌËã±í customer_orders ÖÐËùÓж©µ¥½ð¶îµÄ×ܺͣº

SELECT SUM(order_amount)
FROM customer_orders;

µÇ¼ºó¸´ÖÆ

Ó÷¨

SUM º¯Êýͨ³£Óë WHERE ×Ó¾äÍŽáʹÓã¬ÒÔ¶ÔÌض¨Ìõ¼þϵÄÖµ¾ÙÐÐÇóºÍ¡£ÀýÈ磬ÒÔÏÂÅÌÎÊÅÌËãËùÓÐ×ܶ©µ¥½ð¶îÁè¼Ý 100 ÃÀÔªµÄ¶©µ¥µÄ×ܺͣº

SELECT SUM(order_amount)
FROM customer_orders
WHERE order_amount > 100;

µÇ¼ºó¸´ÖÆ

×¢ÖØÊÂÏî

SUM º¯Êý²»¿ÉÓÃÓÚÇóºÍ NULL Öµ¡£ÈôÊDZ£´æ NULL Öµ£¬Ôò»áºöÂÔËüÃÇ¡£

SUM º¯Êý¿ÉÒÔÓë DISTINCT Òªº¦×ÖÍŽáʹÓã¬ÒÔ¶ÔΨһֵ¾ÙÐÐÇóºÍ¡£

SUM º¯Êý¿ÉÒÔÓë GROUP BY ×Ó¾äÍŽáʹÓã¬ÒÔ¶Ô·Ö×éºóµÄÊý¾Ý¾ÙÐÐÇóºÍ¡£

ÒÔÉϾÍÊÇsqlÖÐsumµÄÓ÷¨½â˵µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ