doesn't work :( , tested with 4.1.21
On 21 Sep 2006 13:20:37 -0000, Felix Geerinckx
<[EMAIL PROTECTED]> wrote:
On 18/09/2006, "Ahmad Al-Twaijiry" wrote:
> I want to run SQL query that will return to me the first records that
> the SUM of Total field = 100
USE test;
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (
id INT UNSIGNED NOT NULL PRIMARY KEY, total INT NOT NULL);
INSERT INTO foo VALUES
(1, 20), (2, 30), (3, 40), (4, 10), (5, 20), (6, 20);
SELECT
f1.id,
f1.total
FROM foo f1
JOIN foo f2 ON f2.id <= f1.id
GROUP BY f1.id, f1.total
HAVING SUM(f2.total) <= 100;
--
felix
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
--
Ahmad Fahad AlTwaijiry
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]