Retrieves the last record of each group

Like the title, retrieve the last record of each group.

For example, prepare some data first:

Share a picture

share picture Source Code

Requirements Group by [Category] and check the record with the largest data in [Qty].

CTE query grouping table:

share picture

SELECT data:

share picture

As long as I get the record with row number 1, it is enough, because in CTE processing, I have already done grouping and sorting by [Category].

share picture

< img alt="Share a picture" id="code_img_closed_f30a2356-1e96-4a8d-9616-c291f4c28343" class="code_img_closed" src="/wp-content/uploads/images/architecture/search-engines/1626814062251.gif"> Source Code

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2762 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.