Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    1 page views
  •   0 video views
  • 2024, October 08, Tuesday

#009 Find the sum of sales grouped by date and product

Como localizar a soma de vendas agrupadas por data e produto em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code performs a query on the "f.Combustibleis" table. I'll explain each part

of the code:SELECT [DATE], [
  1. PRODUCT], SUM([VALOR_VENDA]) THE SalesDay

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [DATE], [PRODUCT]: These are the columns that will be selected in the query.
    • SUM(
    • [VALOR_VENDA]) THE SalesDay: Calculates the sum (SUM) of the "VALOR_VENDA" column for each unique combination of values in the "DATE" and "PRODUCT" columns. The result of this sum is renamed to "SalesDay" for easy reference in the query.
  2. FROM
  3. f.Fuels

    :
    • FROM: Indicates the table from which the data will be selected.
    • f.Fuels: This is the name of the table from which the data will be extracted. The prefix "f." suggests that the table is in a schema called "f".
  4. GROUP BY [
  5. DATA], [PRODUCT]:GROUP BY

    • : Groups the results based on the specified columns, in this case, "DATE" and "PRODUCT". This means that the sum will be calculated for each distinct combination of values in these columns.

Therefore, the code returns the sum of fuel sales grouped by date and product. The results include three columns: "DATE", "PRODUCT", and "SalesDay" (the sum of sales for each unique combination of date and product). This query is useful when you want to analyze aggregate product sales on different dates.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 15 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now