Like the title, retrieve the last record of each group.
For example, prepare some data first:
Requirements Group by [Category] and check the record with the largest data in [Qty].
CTE query grouping table:
SELECT data:
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].
< 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