SELECT SUM(DISTINCT Price) Total_Price FROM Books So, the SUM() function will ignore the duplicate values and NULL values if available in the column values of table. We can also apply the DISTINCT keyword to find out the unique sum value of unique column values. We are going to use the aggregate SUM() function to fetch the total price of the books from the table quantity using the query below:Īs shown above, the sum has calculated the sum of total price from the book column. To view the contents of this Books table let us query the data: We have a table named Books having some fields defined with columns as BookID, BookName, Language and Price. Let us take a table from the database as a demo table to generate the total sum of column table values. Let us evaluate the MySQL SUM() to show the working of sum with the table columns and rows to get the result total set. Since, the SUM() is an aggregate function so it works on multiple table rows or of a table column to find the sum result to return only a value. The tables are also joined with INNER JOIN and applying the USING keyword to specifycolumn name of the table. Here, the syntax shows a CASE statements with SUM() function evaluated for table columns done for the respective tables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |