| |

VerySource

 Forgot password?
 Register
Search
View: 928|Reply: 9

Seeking SQL summary statement.. Master please help us to see

[Copy link]

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-11-26 14:00:01
| Show all posts |Read mode
Table a
clbm,clmc
1 a
2 b
3 c


Table b
clbma,clmca,clgg, jj, sj, flbm
545 a1 re 8.0 8.0 1
434 a2 re 15.2 8.0 1
676 a3 re 9.0 8.0 1
21 b4 re 9.0 8.0 2
54 b1 re 9.0 8.0 2
67 b2 as 9.0 8.0 2
54 c1 d 9.0 8.0 3
23 c2 vc 9.0 8.0 3
5 c3 fd 9.0 8.0 3
54 c4 fd 9.0 8.0 3


The result to be obtained:
1 a
545 a1 re 8.0 8.0 1
434 a2 re 15.2 8.0 1
676 a3 re 9.0 8.0 1
2 b
21 b4 re 9.0 8.0 2
54 b1 re 9.0 8.0 2
67 b2 as 9.0 8.0 2
3 c
54 c1 d 9.0 8.0 3
23 c2 vc 9.0 8.0 3
5 c3 fd 9.0 8.0 3
54 c4 fd 9.0 8.0 3
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-11-26 14:15:01
| Show all posts
select * from(select clbm as clbma,clmc as clmca,clgg='', jj='', sj='', flbm='' from table1
union all
select * from table2)a
order by clmca
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-11-26 14:30:01
| Show all posts
Use FULL JOIN to sort according to the second field
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-11-26 14:45:01
| Show all posts
I've mispoken. . ~-!
, UNION ALL
Reply

Use magic Report

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-11-26 15:00:01
| Show all posts
jj and sj fields are money type
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-11-26 19:45:01
| Show all posts
select * from(select clbm as clbma,clmc as clmca,clgg=NULL, jj=NULL, sj=NULL, flbm=NULL from table1
union all
select * from table2)a
order by clmca

gosh. .
Reply

Use magic Report

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-11-26 20:30:01
| Show all posts
select * from(select clbm as clbma,clmc as clmca,clgg=``, jj='', sj='', flbm='' from gdyj.pubcwcl
union all
select clbma,clmca,clgg,cast(jj as char),cast(sj as char),flbm from dda)a order by clmca

Is not the desired result
Reply

Use magic Report

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-11-26 21:15:01
| Show all posts
Can't sort by clmca field. It will be messy.
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-11-27 02:15:01
| Show all posts
select clbma,clmc,clmca,clgg, jj, sj, flbm from(select clbm as clbma,clmc as clmc,'' as clmca,clgg=NULL, jj=NULL, sj=NULL, flbm=NULL,0 as ord from table1
union all
select clbma,'',clmca,clgg, jj, sj, flbm,1 as ord from table2)a
order by ord,clmca
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-11-27 11:00:01
| Show all posts
I can't sort it yet, I'm very depressed
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list