Now you need to link what query for each user and outbound goods,
Stock_flow table structure
Id primary key
Uid user ID
ProductID commodity ID
The user table structure
Id primary key
The username name
The product table structure
Id primary key
The title product name
I write my own SQL statements
SELECT
A. *,
B.t itle,
C.u sername
The FROM
(select * from stock_flow GROUP BY the uid, productID) a
JOIN the product b ON Amy polumbo roductID=b.i d
Left the join user c ON a.u id=c.i d
The order by a.u id ASC
This basic result, I will
And then explain the
The product table Extra is Using temporary; Using filesort
The user table Extra is Using the where; Using the join buffer (Block Nested Loop)
It is not clear how to optimize, hope comment!
CodePudding user response:
In the column and associated conditions indexDISTINCT replacement GROUP BY
SELECT
A. *,
B.t itle,
C.u sername
The FROM
(select DISTINCT uid, productID from stock_flow) a
JOIN the product b ON Amy polumbo roductID=b.i d
Left the join user c ON a.u id=c.i d
The order by a.u id ASC
CodePudding user response: