-
select [salesman],sum([sales]) all* ,product category from [sales details] a inner join (select [salesman],sum(sales) all from [sales details] inner join ()group by [salesman]) b on a.[Salesman]=b.[Salesman] group by [Salesman], product category.
Personal advice.
-
select sno,type ,count(type)from table group by sno,type
This is vertical, horizontal below.
select sno,sum(case when type='a' then 1 else 0 end) as t_a,sum(case when type='b' then 1 else 0 end) as t_b,sum(case when type='c' then 1 else 0 end) as t_c from table group by sno
-
Grouping makes sense when the array is repeated, because a person can also be divided into a group, but it doesn't make sense, and the grouping is done with a group by statement, and the syntax is as follows:
Example: Group by department number, find the number of people in each department, the average salary.
Group by position to find the maximum and minimum wages for each position:
Once grouped, there are actually new grammatical limitations:
The grouping function can be used alone when there is no grouping, but no other query fields can appear
ename is the other query field. After the select clause, only grouped fields and statistical functions can appear, and no other fields can appear.
Grouping functions are allowed to be nested, but no other fields can appear in the query of the nested grouping function.
Example: Calculate the salary with the highest average salary grouped by position.
When adding another field 'job' I get an error.
Example: Find out the name, location, number of people in each department, and average salary.
Determine the required datasheet:
EMP table: number of people in the department, average salary.
dpt table: the name and location of the department.
Identify known associated fields:
According to the previous understanding of grouping, as long as the data is duplicated, it is possible to query the grouping, but at this time, it is not the same as the previous grouping operation, the previous grouping is grouped for an entity table (emp, dept belong to the entity table), but for the above data is displayed through the query results, so it is a temporary virtual table, but regardless of whether it is an entity table or a virtual table, as long as there is a duplicate, Then let's go straight to the grouping.
-
You need to use group
by statement.
1. Create a test table and insert data
create table test
id int,name varchar(10),score int,classname varchar(20));
insert into test values (1,'Zhang San',100,'One shift');
insert into test values (2,'Li Si',89,'One shift');
insert into test values (3,'Wang V',97,'One shift');
insert into test values (4,'Zhao Liu',87,'Second shift');
insert into test values (5,'Sun Qi',94,'Second shift');
insert into test values (6,'Yang Ba',76,'Second shift');
2. To query the total score of each class, you can use the following statement:
select classname,sum(score) as total score from test group by classname;
3. Screenshot of the result:
Add the field status to varchar(10) in the database table
update database table name set status = from database table name inner join temporary table name b on database table name. qh = and database table name. tel = >>>More
With a view or an index.
create index >>>More
The characters of the MBC drama "Chunzi's Family Has a Happy Event" will be broadcast soon - Kim Ki-bum as Park Jung-woo Park Jung-woo (Kim Ki-bem). >>>More
F get domain contrast is a formatting function (should be written by yourself), the first parameter (arg prod spec id) according to the second parameter (120) formatting and return the result to the v bill code, according to the function naming method, the above ** should be the standard format for getting the date.
It can't be two of the most talented people at the time will not get along well in a camp, we are reading books or **, can not understand the thoughts of those people at that time, it is difficult to say that they will have no desire for power in their hearts, no yearning for merit, if one of them thinks so, then Shu will be even more chaotic. This is one thing, but it also depends on whether the leader can reconcile the talents under his hands. When Liu Bei hung up, Liu Chan estimated that he didn't have the ability to lead them well. >>>More