It would be unrealistic to display all user IDs in a single column as requested by the poster. If the number of users is counted by month, it should be SELECT COUNT(DISTINCT user ID) count,FROM_UNIXTIME(timestamp,' %Y%m') month FROM table GROUP BY month
Can you please stop writing the problem in the code? . . Think about the user experience. . .
Yes, group by can be followed by multiple fields, just separate them with commas.
Can I understand what the poster said
(表中同一个用户ID可能出现多次)
to mean that he wants to get the number of unique users per month?If so, the Sql statement would be like this
If not, that’s it
Use the form count(xxxx) as xxxx_num
It would be unrealistic to display all user IDs in a single column as requested by the poster.
If the number of users is counted by month, it should be
SELECT COUNT(DISTINCT user ID) count,FROM_UNIXTIME(timestamp,' %Y%m') month FROM table GROUP BY month