I want to select the headers (and ID-s) from a table grouped by date, but like below.
The cell on the left is ID
The cell on the right is Title
The middle cell is Date
Select ID
, Title
, Date
BY from the
News group in order of
Date Date
DESC;
P粉7380461722023-09-13 09:16:35
To display grouping by value as a header in MySQL, you can use the GROUP_CONCAT
function in conjunction with the CONCAT
function to concatenate the grouped values with a string. Here is an example query:
SELECT CONCAT('Group:', group_column) AS header, COUNT(*) AS count FROM your_table GROUP BY group_column;
In this query, replace group_column
with the name of the column you want to group by, and your_table with the name of the table. CONCAT
Function combines the string "Group:" with the value of group_column to create a header. The COUNT
function counts the number of rows in each group.
This will generate a result set with two columns: the title column and the count column. The title column will display the group value concatenated with the string "Group:".