| |

VerySource

 Forgot password?
 Register
Search
View: 894|Reply: 7

The data found after adding a condition is not accurate! What's going on?

[Copy link]

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-22 20:30:02
| Show all posts |Read mode
SELECT Stock.GoodsID, Goods.GoodsName,
 Goods.NormalPrice, SUM (Stock.Stock) AS Stock,
(SUM (Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID
GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock

The above is correct.I just add a condition and write:
SELECT Stock.GoodsID, Goods.GoodsName,
 Goods.NormalPrice, SUM (Stock.Stock) AS Stock,
(SUM (Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID AND Stock <3
GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock

After writing this, the inventory quantity found is wrong, what's going on ?!
The structure of the STOCK table is:
ID, GoodsID, WarehouseID, Stock

The above STOCK table may have the same GOODSID but different WAREHOUSEID, I think the problem may be here. For example:
ID GoodsID WarehouseID Stock
1 g1 w1 10
2 g1 w2 5

Thank you!
Reply

Use magic Report

0

Threads

48

Posts

30.00

Credits

Newbie

Rank: 1

Credits
30.00

 China

Post time: 2020-6-30 22:15:01
| Show all posts
SELECT Stock.GoodsID, Goods.GoodsName,
Goods.NormalPrice, SUM(Stock.Stock) AS Stock,
(SUM(Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock
having sum( Stock) <3
Reply

Use magic Report

0

Threads

48

Posts

30.00

Credits

Newbie

Rank: 1

Credits
30.00

 China

Post time: 2020-6-30 23:00:02
| Show all posts
The total number of stocks is less than 3
Your method is a single record less than 3
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-7-1 03:00:01
| Show all posts
Different conditions will definitely give different results
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-7-1 07:30:01
| Show all posts
SELECT Stock.GoodsID, Goods.GoodsName,
Goods.NormalPrice, SUM(Stock.Stock) AS Stock,
(SUM(Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID
GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock
having SUM(Stock.Stock)>3
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-7-1 08:30:01
| Show all posts
Wrong writing is less than 3
Reply

Use magic Report

0

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-3 16:30:01
| Show all posts
"The inventory quantity found after writing this way is wrong, what's going on?"

What does the correct data you want look like?
Reply

Use magic Report

2

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-7-12 17:45:01
| Show all posts
Thanks and learned again.
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