Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Student ID Student Name Student Money
- --------- ----------- --------------
- 1 John 190
- 2 Jenny 290
- 3 Ben 200
- 4 Andy 120
- 5 Lynna 300
- SELECT MAX(N) FROM INTS
- WHERE (SELECT SUM(money) FROM student ORDER BY xxx LIMIT N) < 1000
- SELECT Student.*, SUM(StudentBefore.Money) AS AccumulatedMoney
- FROM (
- SELECT *, ROW_NUMBER() OVER(ORDER BY Id) AS RowNumber
- FROM Students
- ) AS Student
- INNER JOIN
- (
- SELECT *, ROW_NUMBER() OVER(ORDER BY Id) AS RowNumber
- FROM Students
- ) AS StudentBefore
- ON StudentBefore.RowNumber <= Student.RowNumber
- GROUP BY Student.RowNumber, Student.Id, Student.Name, Student.Money
- HAVING SUM(StudentBefore.Money) < 1000
- SELECT s1.ID, s1.name, s1.money, sum(s2.money)
- FROM student s1
- INNER JOIN student s2 ON s1.id >= s2.id
- GROUP BY s1.id HAVING SUM(s2.money) <= 500;
Add Comment
Please, Sign In to add comment