Find a paged query statement of mysql

the database is a mysql, data table with the following contents:

< table > < thead > < tr > < th > mysql > select * from test; < / th > < / tr > < / thead > < tbody > < tr > < td > id < / td > < td > tel < / td > < td > num < / td > < td > time < / td > < td > name < / td > < / tr > < tr > < td > 1 < / td > < td > 13011115652 < / td > < td > 5 < / td > < td > 12 < / td > < td > Liu Xiaoxiao < / td > < / tr > < tr > < td > 2 < / td > < td > 13021115651 < / td > < td > 5 < / td > < td > 12 < / td > < td > Wang Da < / td > < / tr > < tr > < td > 3 < / td > < td > 13036115653 < / td > < td > 5 < / td > < td > 12 < / td > < td > fruit < / td > < / tr > < tr > < td > 4 < / td > < td > 13046115654 < / td > < td > 5 < / td > < td > 12 < / td > < td > < / td > < / tr > < tr > < td > 5 < / td > < td > 13026115650 < / td > < td > 5 < / td > < td > 12 < / td > < td > < / td > < / tr > < tr > < td > 6 < / td > < td > 13026115655 < / td > < td > 5 < / td > < td > 12 < / td > < td > Zhang Xiao < / td > < / tr > < tr > < td > 7 < / td > < td > 13026115656 < / td > < td > 1 < / td > < td > 11 < / td > < td > about < / td > < / tr > < tr > < td > 8 < / td > < td > 13026115657 < / td > < td > 4 < / td > < td > 21 < / td > < td > < / td > < / tr > < tr > < td > 9 < / td > < td > 13026115658 < / td > < td > 6 < / td > < td > 31 < / td > < td > < / td > < / tr > < tr > < td > 10 < / td > < td > 13026115659 < / td > < td > 3 < / td > < td > 11 < / td > < td > < / td > < / tr > < tr > < td > 11 < / td > < td > 13626125651 < / td > < td > 9 < / td > < td > 22 < / td > < td > < / td > < / tr > < tr > < td > 12 < / td > < td > 13633325651 < / td > < td > 10 < / td > < td > 32 < / td > < td > < / td > < / tr > < tr > < td > 13 < / td > < td > 13833445652 < / td > < td > 24 < / td > < td > 120 < / td > < td > six routes < / td > < / tr > < tr > < td > 14 < / td > < td > 13833445644 < / td > < td > 24 < / td > < td > 120 < / td > < td > < / td > < / tr > < tr > < td > 15 < / td > < td > 13833445621 < / td > < td > 34 < / td > < td > 120 < / td > < td > < / td > < / tr > < tr > < td > 16 < / td > < td > 13833448999 < / td > < td > 14 < / td > < td > 110 < / td > < td > < / td > < / tr > < tr > < td > 17 < / td > < td > 13833448839 < / td > < td > 14 < / td > < td > 110 < / td > < td > Happy < / td > < / tr > < / tbody > < / table >

17 rows in set (0.00 sec)

The

sql query statement needs to be sorted by the two fields num (number of calls) descending, name (contact), while paging displays 5 pieces of data per page.

specific sorting requirements: first show that name is not empty (these records whose name is not empty are sorted by num descending order), then show that the remaining name is empty (these name empty records are sorted according to num descending order), and show 5 records limit per page to complete

online and other bosses to solve, thank you very much!

Aug.02,2021

do you have any advice? I've been waiting online all night!


SELECT * FROM (
SELECT * FROM ((SELECT * FROM `fuck` WHERE `name`!='' ORDER BY `num` DESC) AS `NOSHIT`)
UNION ALL
SELECT * FROM ((SELECT * FROM `fuck` WHERE `name`='' ORDER BY `num` DESC) AS `ONSHIT`)
) AS `SHIT` LIMIT 0,5

0 is the number of skipped values for paging. For example, the second page is 5 and the third page is 10.


positive solution upstairs, but I have a question why UNION ALL has an extra layer of select before and after it, otherwise sorting will not work

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34c48-2b791.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34c48-2b791.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?