In my MYSQL Database COMPANY, I have a Table: Worker
:
mysql> DESC `Worker`;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| SSN | varchar(64) | NO | | NULL | |
| name | varchar(64) | YES | | NULL | |
| salary | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
I created using following MySQL's command:
CREATE TABLE `Worker` (
`SSN` varchar(64) NOT NULL,
`name` varchar(64) DEFAULT NULL,
`salary` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
The table having following data:
mysql> SELECT * FROM `Worker` ORDER BY salary ASC;
+-----+---------+--------+
| SSN | name | salary |
+-----+---------+--------+
| 6 | TWO | 50 |
| 5 | ONE | 100 |
| 1 | Grijesh | 200 |
| 3 | Sumit | 250 |
| 2 | Rahul | 300 |
| 4 | Harsh | 500 |
| 7 | THREE | 1000 |
+-----+---------+--------+
7 rows in set (0.00 sec)
its insert query:
INSERT INTO `Worker`
(SSN, name, salary)
VALUES
("1", "Grijesh", 200),
('2','Rahul',300),
('3','Sumit',250),
('4','Harsh',500),
('5','ONE','100'),
('6','TWO',50),
('7','THREE',1000);
[QUESTION]
I wants to select first n workers
(in asc list)those sum of salary is just more than 500 (> 500). for example:
following four workers are first low salary employees and having SUM of salary 600. (600 > 500)
| 6 | TWO | 50 |
| 5 | ONE | 100 |
| 1 | Grijesh | 200 |
| 3 | Sumit | 250 |
I need something like SELECT * FROM
WorkerWHERE SUM(salary) < 501 ASC;
(its incorrect query)
An assumption can be made that all having different salary.
its something like cost cutting: remove employee those are relatively unimportant
A suggestion or link to read will be helpful