1

I have been trying to learn using the Pubs database. I have been trying to figure out how to create a stored procedure to create a profitability column.

The current code I have is this.

SELECT DISTINCT pub_id, ((price * ytd_sales) - advance / 100 * royalty) as [Profit]
FROM titles
WHERE price IS NOT NULL 

The two issues I am having are pub_id contains duplicates since they're sorted using title_id and one publisher can publish more than one book.

I am trying to add all the profits together and only have 1 row per publisher. And I am trying to turn that into a stored procedure.

turbo
  • 1,233
  • 14
  • 36

1 Answers1

0

Do you mean-

SELECT pub_id, sum((price * ytd_sales) - advance / 100 * royalty) as [Profit]
FROM titles
WHERE price IS NOT NULL
GROUP BY pud_id
ORDER BY pub_id
Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24