I have a table like this:
| ID | Class | Marks |
| ------------ | ------------ | ------------ |
| 1 | 12th | 0 |
| 2 | 10th | 25 |
| 3 | 09th | 24 |
| 4 | 12th | 50 |
| 5 | 10th | 60 |
| 6 | 09th | 70 |
The desired output is like this:
Marks | CLass12th | class9th | class10th |
---|---|---|---|
0-25 | 1 | 1 | 1 |
25-50 | 1 | 0 | 0 |
50-60 | 1 | 0 | 1 |
60-70 | 0 | 1 | 1 |
Total | 3 | 2 | 3 |
How can I do the same with SQL?
3条答案
按热度按时间pjngdqdw1#
-----not able to put (0-24) condition in marks as it is actually minus the value as -24 -----
ny6fqffe2#
Try this :
daolsyd03#
You need to store your ranges our use a CTE and use it in a query like this: