I recently encountered a problem when doing IM, and used these three keywords at the same time. It is to query the offline message details of a person. The details returned by our server to the client include three contents. The first one requires to list which people or groups have sent you messages during the offline period. The second one is how many offline messages a certain person or group has sent. The third one is to display the latest one. Obviously, group by groups which people or groups have sent you offline messages, count() gets the number of offline messages, and order by time sorts to get the latest messages. Then, as expected, an error occurs when searching with group by and order by together. We can use nested subqueries. We can group and calculate the number of results that have already been sorted. There is a hidden pit here, which I accidentally avoided. In fact, count() will cause the order by sort to be invalid. For example: The statement finally obtains a record in which msg_data is actually not sorted at all, that is, the original order of the database. It should be the message that was inserted first, that is, the old message. To avoid this problem, the nested subquery is sorted first and then count() is used to avoid it. I dodged it unintentionally, but I discovered it after I modified the sentence and tested it again and again. You may also be interested in:
|
<<: WeChat applet to achieve the revolving lantern effect example
>>: A complete example of Vue's multi-level jump (page drill-down) function for related pages
Preface When the system space usage is too large ...
After the article "This Will Be a Revolution&...
nginx version 1.11.3 Using the following configur...
Table of contents Example Method 1: delete Method...
Solve the problem that the vue project can be pac...
This article records the installation and configu...
Table of contents environment Virtual Machine Ver...
This article shares the MySQL 5.7.18 MSI installa...
We can set a background image for the cell, and w...
Note: There was no error in the project startup d...
Functions about null in MySql IFNULL ISNULL NULLI...
Nginx supports three ways to configure virtual ho...
The key features of the InnoDB storage engine inc...
1. Preparation before installation 1. Download th...
Table of contents Same Origin Policy Ajax request...