Mala Mahadevan

My name is Malathi, a.k.a Mala - I am a DBA turned BI/Data Science person, working with SQL Server since 6.5. I am also founder of the Louisville SQL Server user group, organizer of 8 SQL Saturdays, Regional mentor for northeast, and 14-year PASS conference attendee. In my spare time I love to garden, travel, read, paint, and do yoga.

SQLServerCentral Article

Formatting T-SQL Scripts using ScriptDOM and PowerShell

Well-formatted scripts are always easier to maintain and enhance readability to high degree. Formatting standards are an important part of coding standards anywhere and if not, they need to be. If there are a large number of scripts this can add up to a significant amount of time needed to maintain them. It is also […]

4.4 (5)

You rated this post out of 5. Change rating

2021-08-27

8,861 reads

SQLServerCentral Article

Querying database schema using graph tables

SQL Server 2017 introduced the concept of graph data tables as part of the SQL Server database engine. With SQL Server 2019, there were some enhancements like ‘shortest path’ function and constraints on edge tables that make this feature more usable – although it is far from a full-fledged graph database. Graph tables are essentially […]

4.2 (5)

You rated this post out of 5. Change rating

2019-12-23

15,184 reads

SQLServerCentral Article

Querying Temporal Tables

Temporal tables a.k.a Table Versioning was introduced in SQL Server 2016 and is an easy, convenient way to track changes to data. A good introduction to temporal tables can be found here. One of the key advantages of versioning tables is easy of querying – or getting a ‘single pane of glass’ look of how […]

5 (2)

You rated this post out of 5. Change rating

2019-07-29

14,479 reads

Blogs

Free PostgreSQL Performance Monitoring with pgNow

By

I’ve been putting together a new PostgreSQL session called “Performance Monitoring for the Absolute...

Dealing with Changing Data Formats: Schema Drift in Azure Data Factory

By

(2025-Feb-12) I will jump straight to the problem statement without a "boring" introduction, which, in...

Adding Manual Relationships Between Tables in the TDM Subsetter

By

I wrote about getting the Redgate Test Data Manager set up in 10 minutes...

Read the latest Blogs

Forums

sqlserver metrics to capture

By mtz676

Can this baselining and benchmarking sqlserver be done using extended events ? what are...

SSMS Object Explorer Not Showing Tables

By Ahr Aitch

If this post doesn't meet protocol here, please tell me how to improve as...

Do You Folks Mind Beginners Here?

By Ahr Aitch

I'm a retired IT guy in his 80s fighting boredom by trying to learn...

Visit the forum

Question of the Day

The Rank Window

I have this table and data:

CREATE TABLE [dbo].[SalesTracking]
(
[SalesDate] [datetime] NULL,
[SalesPersonID] [int] NULL,
[CustomerID] [int] NOT NULL,
[PONumber] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[paid] [bit] NULL,
[total] int
) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX [SalesTrackingCDX] ON [dbo].[SalesTracking] ([SalesDate]) ON [PRIMARY]
GO
INSERT dbo.SalesTracking
  (SalesDate, SalesPersonID, CustomerID, PONumber, paid, total)
VALUES
  ('2024-03-15 10:45:55.067', 1, 1,'PO965' ,1, 100),
  ('2023-09-24 10:45:55.067', 1, 2,'PO627' ,1, 200),
  ('2022-07-02 10:45:55.067', 1, 3,'PO6'   ,1, 300),
  ('2022-11-03 10:45:55.067', 1, 4,'PO283' ,1, 400),
  ('2022-11-26 10:45:55.067', 1, 5,'PO735' ,1, 500),
  ('2023-04-28 10:45:55.067', 1, 6,'PO407' ,1, 600),
  ('2022-09-09 10:45:55.067', 1, 7,'PO484' ,1, 700),
  ('2024-03-13 10:45:55.067', 1, 8,'PO344' ,1, 700),
  ('2024-04-24 10:45:55.067', 1, 9,'PO254' ,1, 800),
  ('2022-06-19 10:45:55.067', 1, 10,'PO344',1, 800)
GO
When I run this query, how many unique values are returned for the SalesRank column?
SELECT
  st.SalesDate
, st.SalesPersonID
, st.total
, RANK () OVER (PARTITION BY st.SalesPersonID
                ORDER BY st.total desc) AS SaleRank
FROM dbo.SalesTracking AS st;

See possible answers