Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    2 page views
  •   0 video views
  • 2024, September 03, Tuesday

#006 Retrieve only rows with dates after the date in Azure SQL

Como recuperar apenas as linhas com datas posteriores a 1º de junho de 2022 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 [
  1. DATE], SUM([VALOR_VENDA]) AS TotalSales

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [DATE]: This is the column that will be selected.
    • SUM(
    • [VALOR_VENDA]) AS TotalSales: Calculates the sum (SUM) of the "VALOR_VENDA" column for each record group based on the "DATE" column. 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. WHERE
  5. [DATA] > '20220601'

    :
    • WHERE: Filters results based on a condition.
    • [DATE] > '20220601': The condition specifies that only records whose value in the "DATE" column is later than June 1, 2022 will be included in the query.
  6. GROUP BY [DATA]:GROUP BY

    • : Groups the results based on the specified column, in this case, "DATE". This means that the sum will be calculated for each distinct group of values in the "DATE" column.
  7. ORDER BY [DATA]:ORDER BY

    • : Sorts the results of the query.
    • [DATE]: Sorts the results based on the "DATE" column, in ascending order, i.e. from the earliest to the most recent date.
Therefore, the

code returns the sum of fuel sales grouped by date, considering only records with dates after June 1, 2022, and the results are ordered by date.

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

  • Reading time 1 min 25 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now