TransWikia.com

MySQL nested groupby with count other field

Database Administrators Asked by Jayakusumah on January 8, 2021

I have a table like this:

option question     questionId
  A    question1        1
  A    question1        1
  A    question2        2
  B    question2        2

I want to (use query):

[
  {
    "question": "question1",
    "count": 2,
    "questionId": 1,
    "options": [
      { "value": "A", "count": 2 }
     ]
  },
  {
    "question": "question2",
    "count": 2,
    "questionId": 2,
    "options": [
      { "value": "A", "count": 1 },
      { "value": "B", "count": 1 }
     ]
  }
]

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP