There are three tables (first behavior field name)
User table:
ID |
name |
1 |
Aaa |
2 |
Bbb |
3 |
Ccc |
Chargerecord Recharge Record Table:
ID |
userId |
| Money
1 |
1 |
10 |
2 |
1 |
2 |
3 |
2 |
4 |
4 |
2 |
6 |
Record Call Log table:
ID |
Callid (main call) |
Becallid (called) |
time (length) |
1 |
2 |
1 |
23 |
2 |
3 |
1 |
2 |
3 |
2 |
3 |
16 |
How to make a connection using the ID in the user table and the userid of the Recharge record table and the Callid/becallid
Query the user name, recharge the total amount, and the total length of call (call length)
The novice thanked everybody!!
Reply content:
There are three tables (first behavior field name)
User table:
ID |
name |
1 |
Aaa |
2 |
Bbb |
3 |
Ccc |
Chargerecord Recharge Record Table:
ID |
userId |
| Money
1 |
1 |
10 |
2 |
1 |
2 |
3 |
2 |
4 |
4 |
2 |
6 |
Record Call Log table:
ID |
Callid (main call) |
Becallid (called) |
time (length) |
1 |
2 |
1 |
23 |
2 |
3 |
1 |
2 |
3 |
2 |
3 |
16 |
How to make a connection using the ID in the user table and the userid of the Recharge record table and the Callid/becallid
Query the user name, recharge the total amount, and the total length of call (call length)
The novice thanked everybody!!
SELECT user.id AS id, user.name AS name, charge.money AS money, record.time AS timeFROM userLEFT JOIN (SELECT userId, SUM(money) AS money FROM chargerecord GROUP BY userId) AS charge ON user.id = charge.userIdLEFT JOIN (SELECT callId, SUM(time) AS time FROM record GROUP BY callId) AS record ON user.id = record.callIdORDER BY user.id
How to check upstairs has been given I have an article about multi-table query to the landlord to understand more than one table query helpful: Several connections of SQL: Internal connection, leftist, right connection, full connection, cross connection
If you don't like the answer to the comment, I'll take it back, please don't step on it.