Home > database >  How to use an SQL statement to implement?
How to use an SQL statement to implement?

Time:09-21

A figure has four data, how to use an SQL statement to achieve statistical merged, effect as shown in figure 2,

CodePudding user response:

A statement, I didn't find method. Can this: build a crosstab first, and then query.
To ensure the queries for tb1_ crosstab: TRANSFORM the Count (tb1. Model) model AS the calculation of the SELECT tb1. The shaft type FROM tb1 GROUP BY tb1. The PIVOT shaft type tb1. The state;
And then to a query: SELECT tb1_ crosstab. Shaft type, tb1. Models, tb1_ crosstab. Wear good, tb1_ crosstab. Not wear, tb1_ crosstab. Not play reed, tb1_ crosstab.
in wearThe FROM tb1 INNER JOIN tb1_ crosstab ON tb1. The shaft type=tb1_ crosstab. Shaft type
GROUP BY tb1_ crosstab. Shaft type, tb1. Models, tb1_ crosstab. Wear good, tb1_ crosstab. Not wear, tb1_ crosstab. Not play reed, tb1_ crosstab. Wear;
Don't know this line not line.

CodePudding user response:

Select a. *, b. in wear, c. not to wear, d. not dozen reed from
(select shaft type, type, name, batch number, head of the count (*) as good wear the where state="wear") a
Left the join
(select shaft type, type, name, batch number, head of the count (*) as the where in wearing status="wearing") b on a. shaft type=b. shaft type and a. models=b. models and a. name=b. name and a. batch number=b. batch number and a. head a=b. Copy of
Left the join
(select shaft type, type, name, batch number, head of the count (*) as did not wear the where state="not to wear") on a. c axis type=c. shaft type and a. models=c. models and a. name=c. name and a. batch number=c. batch number and a. head a=c. Copy of
Left the join
(select shaft type, type, name, batch number, head of the count (*) as not dozen reed where state="did not play reed") d on a. shaft type=d. shaft type and a. models=d. model and a. name=d. name and a. batch number=d. batch number and a. head a=d. copy of

CodePudding user response:

Select a. *, b. in wear, c. not to wear, d. not dozen reed from
(select shaft type, type, name, batch number, head of the count (*) as good wear the where state="wear" group by shaft type, type, name, batch number, head of) a
Left the join
(select shaft type, type, name, batch number, head of the count (*) as the where in wearing status="wearing" group by shaft type, type, name, batch number, head) b
On a. shaft type=b. shaft type and a. models=b. models and a. name=b. name and a. batch number=b. batch number and a. head a=b. Copy of
Left the join
(select shaft type, type, name, batch number, head of the count (*) as did not wear the where state="not to wear" group by shaft type, type, name, batch number, head) c
On a. axis type=c axis type and a. models=c. models and a. name=c. name and a. batch number=c. batch number and a. head a=c. Copy of
Left the join
(select shaft type, type, name, batch number, head of the count (*) as not dozen reed where state="did not play reed" group by shaft type, type, name, batch number, head) d
On a. shaft type=d. shaft type and a. models=d. model and a. name=d. name and a. batch number=d. batch number and a. head a=d. copy of

The write wrong just now
  • Related