当前位置:网站首页>Bi-sql order by

Bi-sql order by

2022-06-24 04:47:00 Powerbi white tea

ORDER BY sentence

ORDER BY sentence , stay SQL Can usually be used as a sort basis for query results . Of course. PowerBI Of DAX Also in grammar ORDER BY, It's just usually with EVALUATE Statement collocation .

In actual use DAX In the process of function ORDER BY The appearance rate of the function is not particularly high , Only certain functions can be used with this , and , stay BI In demand , Functions that have special sorting requirements for the returned results are RANKX Functions and TOPN Function .

We often use interface operation “ Sort by column ” function . But in SQL In the syntax ,ORDER BY The frequency of using functions can be said to be quite high .

Basic grammar

SELECT  Column name  FROM  The name of the table  ORDER BY  Column name 

Optional parameters

ASC: Ascending sort

DESC: null

Using examples

Case data :

In the native database of white tea , There is a name “TEST” The database of , There is a name “ Sales details ” Case data for .

Example 1:

Re import the branch column to PowerBI in , Sort in ascending order .

SELECT
      DISTINCT
       The branch where you are 
      FROM
       Sales details 
      ORDER BY
       The branch where you are 
      ASC

give the result as follows :

Example 2:

Re import the branch column to PowerBI in , Sort in descending order .

SELECT
      DISTINCT
       The branch where you are 
      FROM
       Sales details 
      ORDER BY
       The branch where you are 
      DESC

give the result as follows :

Example 3:

Import the customer serial number and the branch to PowerBI in , The customer serial number is sorted in ascending order , Descending sort of branch .

SELECT
       Customer serial number ,
       The branch where you are 
      FROM
       Sales details 
      ORDER BY
       Customer serial number 
      ASC,
       The branch where you are 
      DESC

give the result as follows :

Example 4:

Import the customer serial number and the branch to PowerBI in , Customer serial numbers are sorted in descending order , Sort the stores in ascending order .

SELECT
       Customer serial number ,
       The branch where you are 
      FROM
       Sales details 
      ORDER BY
       Customer serial number 
      DESC,
       The branch where you are 
      ASC

give the result as follows :

This is white tea , One PowerBI Beginners .

原网站

版权声明
本文为[Powerbi white tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/09/20210904093735186z.html