Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I write an SQL query that lists a set of detail rows with a total at the bottom?

lists query rows sql total write
0
Posted

How can I write an SQL query that lists a set of detail rows with a total at the bottom?

0

You can use a UNION operation to append the total as a row at the end of the list of items, as illustrated in the following example: SELECT ‘ITEM’ AS ROWTYPE, PARTID, PRICE FROM PART UNION SELECT ‘TOTAL’ AS ROWTYPE, 0 AS PARTID, SUM( PRICE ) AS PRICE FROM PART ORDER BY ROWTYPE, PARTID To make sure that the total row is at the end of the result set, you must include the Order By clause.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123