A stored procedure was recently written by lone wolf. The approximate content is to query the total order amount of each person, using Table Association, and the execution speed is acceptable. If you have any good suggestions or questions, please let us know more.
There are two tables below
Userinfo table
Order table
If you want to query the total order amount of each person, the first method is to use a loop, but this method is not only complicated, but also slow to execute, which is not recommended by lone wolf. The second method is to associate the table mentioned in this article. The statement is as follows:
Select UI. ID, UI. Name, isnull (X. totalmoney, 0.0) totalmoney from DBO. userinfo UI
Left join
(Select sum (money) as totalmoney, userid from [order] group by userid) X on UI. ID = x. userid
The following result is displayed:
The lone wolf only knows these two methods, but there must be other methods. I will share them with you later. If I know something, I hope I can come up with them and learn from each other, mutual progress.