| |

VerySource

 Forgot password?
 Register
Search
View: 4129|Reply: 20

group by question

[Copy link]

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-22 12:40:01
| Show all posts |Read mode
Hello everyone, I have problems when doing GROUP by, I ask
select a, b, c, sum (num) group by a, b where c is a problem if you do n’t add the summary field, but adding it is time-consuming. What is a good solution? My field must be possible No more than three, select a, b, c, e, f, g, sum (num) group by a, b Do you have to add all the fields later?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 13:45:02
| Show all posts
select a, b, min (c), sum (num) group by a, b
See your specific needs
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-1 15:45:01
| Show all posts
Do all fields have min added? I want this SQL to return the data in all the fields in my table! If you add all the fields after group by, it will take too much time!
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-2-1 15:54:01
| Show all posts
When specifying GROUP BY, all columns in any non-aggregate expression in the select list should be included in the GROUP BY list, or the GROUP BY expression must exactly match the select list expression.
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-2-1 16:00:01
| Show all posts
If column C is not added
Only specified aggregate functions (sum, min, max, count, avg, stdev ....)
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-1 16:54:01
| Show all posts
If it is me, is it the only way to add all fields after group by?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 17:00:02
| Show all posts
You don't understand the meaning of grouping
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Unknown

 Author| Post time: 2020-2-1 20:36:02
| Show all posts
Yes, I may not understand the concept of grouping, but I encountered this problem on the project, that is, when I bind the GRID, my GRID column must contain all the fields in the table, and the summary column is added, although I added all the fields after GROUP by, but the query speed is slow! But there are only two columns in my summary column!
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 22:45:01
| Show all posts
How do the columns after the aggregation correspond to other columns? If the other columns are the same, add min or max.
In addition, increasing the number of fields in the query itself will affect efficiency. .
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-2 09:27:01
| Show all posts
Thank youprajna, SELECT C_CODE, C_NAME, SUBSTRing (F_CODE, P_NSTYLSTAR, P_NSTYLLEN) FA_CODE, F_NAME
      FA_NAME, F_PRICE FA_PRICE, SUM (NUM_1) NUM_1, SUM (NUM_1 * F_PRICE)
      SUM_1 GROUP BY C_CODE, FA_CODE ORDER BY C_CODE, FA_CODE
     FROM PERCUR1
This is my source code, C_code is the store name code, C_NAME is the store name, FA_code is the clothing code, FA_NAME is the clothing name, FA_PRICE is the price, NUM_1 is the number of pieces, the latter column is the amount, I need so much data, but I must It is correct to add all the fields after GROUP by, and I only need to summarize C_code and FA_code. Is it necessary to add all the fields, or there are other good solutions!
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