How to make a statistical data interface with multiple select count,MySQL can be regarded as an efficient interface.

for example, if you do a SQL query of statistical data, the tables come from all directions and have different conditions. If multiple select count are efficiently implemented in a SQL statement, only SQL is considered here. For example, sql is as follows (there is very little data here)

clipboard.png

this kind of SQL, sentence, how to optimize, or simplify SQL, this is part of the sql. As you can see from the example, there are several categories, most of which are written in business, and the technical code has not been studied yet. Please give us some comments.

Note: the X in count (X) is the table"s self-growing primary key ID, and the MySQL version is 8.0

.
Jul.14,2022

you can consider using group by if it is the same table, but there is no good way to use different tables.
count (*) in PS:MYSQL is more efficient than count (field)


if there is no performance problem, you have no problem. Of course, just cache it.
and use explain to analyze
your subquery can also split 2 sql
`
select count (*), type as cnt fromo article where openID in = 43 group by type

select count (*) from diary where openId=43 and type='public'
`

then splice the returned array in the business.

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-1c56c22-34ff6.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-1c56c22-34ff6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?