×ðÁú¿­Ê±

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
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿