Total_Sales 表格 Name Sales John 10 Jennifer 15 Stella 20 Sophia 40 Greg 50 Jeff 20 要算出累積總計,我們就鍵入以下的 SQL 語句: SELECT a1.Name, a1.Sales, SUM(a2.Sales) Running_Total FROM Total_Sales a1, Total_Sales a2 WHERE a1.Sales <= a2.Sales OR (a1.Sales=a2.Sales AND a1.Name = a2.Name) GROUP BY a1.Name, a1.Sales ORDER BY a1.Sales DESC, a1.Name DESC; 結果: Name Sales Running_Total Greg 50 50 Sophia 40 90 Stella 20 110 Jeff 20 130 Jennifer 15 145 John 10 155 var sql = SELECT a1.Name, a1.Sales, SUM(a2.Sales) Running_Total FROM ? a1, ? a2 WHERE a1.Sales <= a2.Sales OR (a1.Sales=a2.Sales AND a1.Name = a2.Name) GROUP BY a1.Name, a1.Sales ORDER BY a1.Sales DESC, a1.Name DESC; " Com_data = alasql(sql, [ Total_Sales , Total_Sales ])
From the Command Line Use the following command to check the version of your local MySQL server. This command is not specific to any operating system. This command is compatible with all Linux, Windows, and macOS versions running MySQL. mysql -V Here is the output. # mysql -V mysql Ver 14.14 Distrib 5.7.15, for Win32 (AMD64) SELECT VERSION Statement Use the SELECT VERSION() command in the MySQL database client to check the MySQL version. SELECT version(); Here is the output. MariaDB [***]> SELECT version(); +-----------------+ | version() | +-----------------+ | 10.3.37-MariaDB | +-----------------+ 1 row in set (0.000 sec)
檢查排程是否有開啟 SELECT @@event_scheduler; SELECT @@global.event_scheduler; 設定開啟 SET GLOBAL event_scheduler = ON ; How to force an event to execute in MySQL Move all the code within the event into a stored procedure Make the event only call the stored procedure Test the stored procedure with the CALL syntax.
留言
張貼留言