-2

I have a big task that I need some help with.

My goal is the following table structure:

enter image description here

type: type of car number_of_cars: number of cars for each car type number: number of people driving each car type average: average number of people driving each car type median: number of people driving each car type max: max value of people driving each car type min: min value of people driving each car type standard deviation: standard deviation of number of people driving each car type

My data table looks like the following:

id    type      people
-----------------------
1     subaru    1
2     bmw       5
3     tesla     2
4     tesla     3
5     subaru    4
6     tesla     1
7     tesla     3
8     subaru    1
9     bmw       5
10    subaru    7
11    subaru    7
12    ford      2
13    ford      4
14    subaru    6
15    ford      3
16    tesla     2
17    tesla     1
18    tesla     1
19    tesla     1

Where id is a unique identifier, type is the type of car, and people is the number of people driving this car.

How do I create one giant MySQL query that gives me the results I need for my table?

Help is appreciated!

Ps. I know that MySQL is not necessarily the best approach to gather statictical data like this, but it should be possible, right?

malhel
  • 61
  • 7
  • 1
    . . Are you familiar with `group by`? Almost everything you want to calculate is easily handled by an aggregation query. – Gordon Linoff Apr 22 '20 at 13:46

1 Answers1

0

All data the statistical data you want can be gathered using GROUP BY statement and built-in functions of mysql. Simply read about aggregate functions in mysql.

Only thing you won't find there is median. Mysql doesn't have built-in function for that but you can easily find some way to do that just by googling it

Kacper
  • 520
  • 5
  • 20