To calculate a subtotal in PostgreSQL, you can use the SUM() function to add up the values of a selected column. First, you need to write a SELECT query to retrieve the desired data. Then, use the SUM() function in conjunction with GROUP BY to calculate the subtotal based on the grouping criteria. For example, if you have a table with columns for product name and price, you can calculate the subtotal for each product category by grouping the results by product name and summing up the prices.