Buy order table, three fields, userid, goodid, time
Click click table, but also the three fields, userid, goodid, time
The user may click a commodity for many times, the last part order,
Now to query to the same user place the order with the same goods before last click on time, and then return to the time,
(under the same commodity most users will only be a single time)
Thank you!
CodePudding user response:
You such a design is problematic, click and order itself has nothing to do, click on the don't place the order, the order can also click again, need to consider the business scenarioRough statement as follows, for your reference
The select userid,
Goodid,
Time,
(select Max (click time)
The from the click
Where the click. Userid=buy. Userid
And the click. Goodis=buy. Goodid
And click the time & lt; .=buy time) as order_time
The from buy;
CodePudding user response:
According to the descending order for the first time the second, and then computing timeCodePudding user response:
If you click on the order with you once the zha