Home > database >  Mysql multi-column sorting, conditions for the other columns?
Mysql multi-column sorting, conditions for the other columns?

Time:10-01

Province number j c s city node number num
S1 C1 J1 3
S2 C2 J2 2
S1 C1 J3 1
S3 C1 J4 5
S3 C2 J5 4
S3 C3 J6 10

The table name temp

I think according to the city, to collate node number, and then for nodes in every city, by the number of node size, from big to small, the output node number, the effect the following
Cities, the total number of nodes, node number, number of node
C1 9 J4 5
C1 9 J1 3
C1 J3 1
C2 6 J5 4
C2 6 J2 2
C3 10 J6 10

Consult everybody what to do, thank you


C2 6 (2 + 4)
C3 10

CodePudding user response:

The select chengshi, (select sum (num) from TB where A.c=c), j, num
The from TB A
The order by c, num
  • Related