| |

VerySource

 Forgot password?
 Register
Search
Author: angelk1983

group by question

[Copy link]

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-2-17 16:30:01
| Show all posts
The use of group by does not seem to understand
If there is sum max avg. . . If there are aggregation parameters, there must be a group by
A big analogy. If you add up all the values ​​of a certain field, then if the other field is not the same as the system, it will not be recognized. You should add that column.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-20 00:00:01
| Show all posts
select TB. *, N.num1 from TB inner join (select a, b, sum (num) as num1 from TB group by a, b) as N On N.a = TB.a order by N.a

This idea may work, but this statement may be incorrect.
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-8 20:15:01
| Show all posts
I'm afraid there aren't many good ways
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-14 18:45:01
| Show all posts
Supportgaara1985, use the column to be grouped as a subquery and then join the original table, but not necessarily inner join, it may be left join or right join, depending on your needs
Reply

Use magic Report

0

Threads

22

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-16 22:00:01
| Show all posts
select b.C_CODE, b.C_NAME, SUBSTRing (b.F_CODE, P_NSTYLSTAR, P_NSTYLLEN) FA_CODE, b.F_NAME FA_NAME, b.F_PRICE FA_PRICE, a.NUM_1, a.SUM_1 from percur1 b inner join (select c_code, f_code, sum (num_1) num_1, sum (num_1 * f_price) sum_1 from percur1 group by c_code, f_code) a on b.c_code = a.c_code and b.f_code = a.f_code

Try this, but I don't know how fast it is. Ha ha
Reply

Use magic Report

0

Threads

22

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-20 10:00:02
| Show all posts
Finally, I missed an order by ....
Reply

Use magic Report

1

Threads

13

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-3-20 12:45:01
| Show all posts
select a, b, sum (num) from table1 aaa group by a, b
union
select a, b, c from table1 bbb group by a, b
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-20 14:15:01
| Show all posts
Algorithmically, all of the above

However, if there are only a few fields, I am afraid that moving 2 or 3 fields will not be too bad in terms of subquery efficiency. If this difference is large, you should split the table structure design (outside words ~)

Moreover, SUBSTRing (F_CODE, P_NSTYLSTAR, P_NSTYLLEN), I doubt whether F_CODE is the same if SUBSTRing (F_CODE, P_NSTYLSTAR, P_NSTYLLEN) is the same. If they are different, you need to consider filtering the results or the inner subquery is SUBSTRing (). . .
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-3-25 19:00:02
| Show all posts
good question!
study ~~~
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Philippines

Post time: 2020-3-28 14:00:02
| Show all posts
If you query a lot of information, the speed will be very slow. Grouping is mainly used in conjunction with aggregate functions. Group by followed by one or two groupings is fine. It is useless if it is more than what you want.
    The main reason is that it is too slow to query too much information. It is recommended that you add top (the number of rows to be queried) or top 20 percent to display the percentage when you query.
    If you have a lot of information, there is nothing you can do about it.
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