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

#002 Sort by clustered value in Azure SQL

Como ordenar 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 against a database that has a table named "f.Moeda_Cotacoes". I'll walk you through step-by-step what each

part of the code does:SELECT
  1. CURRENCY, AVG(TAXA_VENDA) AS VENDA_MED

    :
    • 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) AS VENDA_MED: Calculates the average (AVG) of the "TAXA_VENDA" column for each group of records based on the "CURRENCY" column. The result of this average is renamed to "VENDA_MED" for easy reference in the query.
  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. ORDER BY
  7. VENDA_MED DESC:ORDER BY

    • : Sorts the results of the query.
    • VENDA_MED DESC: Sorts the results based on the "VENDA_MED" column in descending order (DESC), i.e. from highest to lowest. This means that the coins with the highest average of "TAXA_VENDA" will be displayed first.

Therefore, the code returns the average of the selling rates ("TAXA_VENDA") grouped by currency ("CURRENCY") from the "f.Moeda_Cotacoes" table. The results are sorted in descending order by the average sale ("VENDA_MED").

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

  • Reading time 1 min 30 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now