Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    2 page views
  •   0 video views
  • 2024, August 16, Friday

#013 Filter by clustered value in Azure SQL

Como filtrar por valor agrupado 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.Moeda_Cotacoes" table. I'll explain each part

of the code:SELECT
  1. CURRENCY, AVG(TAXA_VENDA)

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • CURRENCY: This is the column that will be selected.
    • AVG(TAXA_VENDA): Calculates the average (AVG) of the "TAXA_VENDA" column for each group of records based on the "CURRENCY" column.
  2. FROM
  3. f.Moeda_Cotacoes

    :
    • FROM: Indicates the table from which the data will be selected.
    • f.Moeda_Cotacoes: 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 CURRENCY:
  5. GROUP BY:

    • Groups the results based on the specified column, in this case, "CURRENCY". This means that the average will be calculated for each distinct group of values in the "CURRENCY" column.
  6. HAVING AVG(TAXA_VENDA) >

    5:
    • HAVING: Filters the group results based on a condition after aggregation, in this case, the condition is that the mean of the "TAXA_VENDA" must be greater than 5.

Therefore, the code returns the average of the sell rates ("TAXA_VENDA") grouped by currency ("CURRENCY"), but only includes the results where the average sell rate is greater than 5. This query is useful when you want to filter aggregated data groups based on a specific condition.

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