| |

VerySource

 Forgot password?
 Register
Search
View: 1142|Reply: 5

Can't sum be used in two tables?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-19 21:00:01
| Show all posts |Read mode
The total data is incorrect
SELECT SUM (a.a) AS AA, SUM (b.b) AS BB
FROM a, b
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-4-27 20:45:01
| Show all posts
SELECT SUM (a.a) AS AA, SUM (b.b) AS BB
FROM a, b
===============
You are the calculated Cartesian product, of course, it is wrong, you should add the associated conditions, namely:
SELECT SUM (a.a) AS AA, SUM (b.b) AS BB
FROM a, b
where a. primary key = b. primary key
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-27 23:30:01
| Show all posts
yes
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-4-27 23:45:02
| Show all posts
ls positive solution ..
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-4-29 22:00:01
| Show all posts
If you really want Cartesian multiplication, where 1 = 1 is fine
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-4-29 23:15:02
| Show all posts
--try

select
AA = (select sum (a) from a),
BB = (select sum (b) from b)
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