Table B store user badge information
Two tables for UID is
Each user may have more than one badge
How to do a query in mysql statement for multiple user information, user information to nested badge information
Also please comment
Expectations get the json data
[{
UserName: "zhang",
UID: 1,
The badge: [{badgeLevel badgeName: "membership" : "1"}]
},
{
UserName: "bill,"
UID: 1,
Badge: [{badgeLevel badgeName: "membership" : "1"}, {badgeLevel badgeName: "association" : "1"}]
}, {
UserName: "detective",
UID: 1,
The badge: null
}]
CodePudding user response:
The SELECT b1. The userName, b2 badgeName, b2. BadgeLevel from user1 b1 INNER JOIN badge on b1, b2 uiduid=b2.
This can query the basic information of each user and badge information, and then you traverse the assembly into a json format you want to
CodePudding user response:
Two table LianZha join tryCodePudding user response:
Background processing code, use the Iterator traversal, using a TreeMap additional ListCodePudding user response: