Home > database >  MYSQL how multiple conditions find and sum the data
MYSQL how multiple conditions find and sum the data

Time:05-01




SQL table content as shown in figure, I want to know how statistics order quantity for each product drawing number, remark as "finished" not statistical
For specific instructions how to write

CodePudding user response:

SELECT COUNT (DISTINCT order number) FROM the name of the table A WHERE A. Note!='finished' GROUP BY a. product figure number

CodePudding user response:

I is to number the field sum, not the number of

CodePudding user response:

. Combined ah, I thought that you ask is how much order

SELECT SUM (a.) FROM the table name A WHERE A. Note!='finished' GROUP BY a. product figure number

CodePudding user response:

Thank you very much, have to you
There is a problem, that is, how to query different two table data
For example, the query table combined, the corresponding figure number in another table lookup inventory combined

CodePudding user response:

SELECT * FROM (
SELECT a. product drawing no., the SUM (a.) FROM table 1 A WHERE A. Note!='finished' GROUP BY a. X1 product drawing no.)
LEFT the JOIN (
SELECT a. product drawing no., the SUM (a. inventory) FROM table 2 A WHERE A. Note!='finished' GROUP BY a. product drawing no.) X2
ON the X1. Product drawing no.=X2. Product figure number
  • Related