Skip to content

Latest commit

 

History

History
72 lines (40 loc) · 1.15 KB

function.md

File metadata and controls

72 lines (40 loc) · 1.15 KB

Function

RANK

RANK() OVER (ORDER BY f DESC) returns the rank position relative to the expression f.

  RANK() OVER (ORDER BY f DESC) 

1.In this example we show the ranking, by population of those countries with a population of over 180 million.

SELECT name,population,
       RANK() OVER (ORDER BY population DESC) AS rank_population
FROM world WHERE population>180000000
ORDER BY name


for i in rank(1, len(rows)):
    rank[i] = dit_rank(population values)
  1. You can see view the RANK according to continent. This shows the biggest country
SELECT
 name,population,
 RANK() OVER (ORDER BY population DESC) AS world_rank,
 RANK() OVER (PARTITION BY continent ORDER BY population DESC) AS local_rank
FROM world WHERE population > 100000000
ORDER BY name

Current_Timestamp

SELECT CURRENT_TIMESTAMP();

DATEPART()

SELECT DATEPART(month, '2017/08/25') AS DatePartInt;

SUBSTRING

Example

Extract a substring from a string (start at position 5, extract 3 characters):

SELECT CustomerName,SUBSTRING(CustomerName, 2, 5) AS ExtractString
FROM Customers;