lundi 19 février 2018

SQLite take N rows per each group

I have an SQLite table similar to the following:

| A | B |
_________
| e | 5 |
| f | 7 |
| a | 5 |
| n | 7 |
| g | 5 |
| d | 7 |
| i | 5 |
| j | 5 |
| e | 7 |
| v | 7 |

How can I retrieve three random rows with value 5 in column B and three random rows with value 7? Result may be not grouped by column B values. It could be something like:

| A | B |
_________
| e | 5 |
| g | 5 |
| e | 7 |
| v | 7 |
| j | 5 |
| f | 7 |




Aucun commentaire:

Enregistrer un commentaire