如何在MYSQL中获得具有子分组的对象数组?

I have the following Rows in my Database:

| id | status | user |
| 1  |   2    | user1|
| 2  |   1    | user2|
| 3  |   2    | user1|
| 4  |   1    | user1|

Now i am trying to return array of obkects where:

  • param 1 is user column
  • and inside param 2 are all rows grouped by status column

This is an example of what i am trying to accomplish:

series: [
        {
          name: "user1",
          data: [1, 2]
        },
        {
          name: "user2",
          data: [0, 1]
        }
      ]

I am hoping there is a why without using php. But if no how can i do it using php pdo?