0

Suppose now i have some table

studentId studentScore ScoreDetail     StudentName Phone  classId Subject     
1          50          (a json value)  Doe         911    01      math

the json file is like

{
  "DetailList": [
    {
      "source": "homework",
      "count": 30,
      "user_id": 1,
      "order_id": ": 0
    },
    {
      "source": "homework",
      "count": 20,
      "user_id": 1,
      "order_id": ": 0"
    }
  ],
  "TotalScoreCount": 50
}

How do i make it into this

studentId   Score  ScoreSource  StudentName Phone  classId Subject
    1         30     homework       Doe       911    01      math
    1         20     homework       Doe       911    01      math
...

Let's say i have 10 student

1
  • 2
    JSON functions are higly vendor-specific. Please tag your question with the database you are running: mysql, oracle, sqlserver...? Commented Nov 20, 2020 at 10:33

1 Answer 1

0

use OPENJSON to parse and transform

https://learn.microsoft.com/en-us/sql/relational-databases/json/convert-json-data-to-rows-and-columns-with-openjson-sql-server?view=sql-server-ver15

Sign up to request clarification or add additional context in comments.

1 Comment

@BQ Learning Check this stackoverflow.com/questions/47104722/… . I trust it give you a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.