Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    8 page views
  •   0 video views
  • 2024, October 18, Friday

#007 Group the rows by a function in Azure SQL

Como agrupar as linhas por uma função 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.Combustiveis" table. I'll explain each

part of the code:SELECT MONTH([DATE]) AS
  1. MesNum, SUM([VALOR_VENDA]) AS TotalSales

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • MONTH([DATE]) AS MesNum
    • : Calculates the number of the month (from 1 to 12) based on the "DATE" column and renames this column to "MesNum".
    • SUM(
    • [VALOR_VENDA]) AS TotalSales: Calculates the sum (SUM) of the "VALOR_VENDA" column for each group of records based on the month number. The result of this sum is renamed to "TotalSales" 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 MONTH([DATE]):
  5. GROUP BY: Groups the results based on the specified expression or column, in this case, "

    MONTH([DATE

    • ])". This means that the sum will be calculated for each distinct group of values in the month number.
Therefore, the code returns the sum

of fuel sales grouped by month number, and the results include two columns: "MesNum" representing the month number and "TotalSales" representing the sum of sales for each month.

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

  • Reading time 1 min 13 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now