mardi 1 septembre 2015

SQL compare each value of column to all values of row from another table

I have two tables StudentTable and LevelsTable. I'm using Java and Sqlite.

my first table : StudentTable

+----+-----------+-------------+-----------+---------------+ | idS| firstName | famillyName | age | pushUps |
+----+-----------+-------------+-----------+---------------+ | 1 | a | d | 17 | 20 | | 2 | b | e | 18 | 30 | | 3 | c | f | 19 | 50 | +----+-----------+-------------+-----------+---------------+

my second table: LevelsTable

+----+-----------+--------+-----------+--------+--------------+ | idP| veryWeak | weak | average | good | veryGood | +----+-----------+--------+-----------+--------+--------------+ | 1 | 10 | 15 | 20 | 30 | 40 | +----+-----------+--------+-----------+--------+--------------+

I want to count the number of students for each level depending on how many pushups do each one. For example : if i have 1000 students, i want to get a result like that :

  • 100 students ∈ [10,15[ --> very weak
  • 250 students ∈ [15,20[ --> weak
  • 400 students ∈ [20,30[ --> average
  • 150 students ∈ [30,40[ --> good
  • 100 students > 40 --> very good.

What do you suggest for a solution??

Aucun commentaire:

Enregistrer un commentaire