score:8
Accepted answer
You need to remove the partition by clause from your query. Just use order by clause.
SELECT ProdID, Years, Months, Quantity,
DENSE_RANK()OVER (Order By Years, Months) Ranks
FROM Products
score:1
The following query should do what you want:
SELECT
ProdID, Years, Months, Quantity,
DENSE_RANK()OVER (ORDER BY CAST(CAST(MONTHS AS VARCHAR)+'-01-'+CAST(YEARS AS VARCHAR) AS DATE)) Ranks
FROM Products
More questions
- How to make Ranking based on Year and Month?
- How to get date to be the same day and month from one variable but in the year based on another variable?
- How to select all data based on year and month
- How to create a Date in SQL Server given the Day, Month and Year as Integers
- SQL Server date comparisons based on month and year only
- How to Partition a Table by Month ("Both" YEAR & MONTH) and create monthly partitions automatically?
- SQL: how to retrieve data in month and year range
- How to get the last day for each month in a distinct year based on a field
- How to exclude weeks based on Year and Week columns?
- How to format year and month only, from a bulk insert
- ORDERING CROSS TAB QUERY BASED ON MONTH AND YEAR
- SQL Query with JpaRepository: how to filter LocalDateTime based only on year, month and day?
- How to return only the year and month from a SQL Server DateTime datatype
- Get date field based on Month and Year
- How to get number of days from month and year
- How to get month and year from date in SQL
- How to group by month and year and also separate the entries?
- How do I return 60 sets of month and year data in a month and year column?
- Custom ID column based on year and month
- How to get latest salary of each associate in sql, table have month and year column also. each associate have minimum 4 to 5 records
- How to add year and end of month in sql query
- SQL to calculate age based on year and month
- How to convert a date column in TSQL to display only the month and year
- How to get results only having month and year for the date?
- How to check if a month and year lies between 2 dates
- How do I fix date in sql server that does not have a proper Day, Month and Year order
- In sql server how to get get All Month and year from given date
- How do I get to choose year and month along with date in SSRS Date Picker (Calendar) Control?
- How can I make Data Flow column mapping Dynamic in Azure Data Factory based on different column names of Source and target?
- How to arrive Last Year Week to Date and Month to Date in SQL?
More questions with similar tag
- Dynamically update "Status" column after "X" amount of time
- Rolling Running total over last 7 days by date and not bound by rows preceding but rather dates preceding for each row in a SQL Table
- Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object
- Selecting row as many times as it was mentioned in WHERE in SQL Server
- Create dummy data with WHILE
- Declare a table in sql
- Stored procedure in SQL Server; syntax error
- T-SQL: Move rows from one table to another, log both source and destination primary keys
- Error: "OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found ..."
- TSQL syntax for updating with inner join
- how to manage more then one request at a same time to the database?
- Developing a recursive/hierarchy query
- How to best generate a unique user number without duplicates in a multi-tenant database
- connect to sql "server group" with php to run query over multiple databases
- How to efficiently prune data
- SQL Copy row in a table with relations
- SQL ROW_NUMBER OVER syntax
- Return records with counts for the last 24 hours
- COUNT(1) + COUNT(DISTINCT()) much slower then doing 2 queries separately
- how to update data from list view to database in asp.net?
- Bulk CSV File Import in MySQL Removing duplicates while Importing dynamic colmns from CSV
- SQL Server: SUM numeric value but leave strings as is
- The wait operation timed out
- Selecting same column list for different where conditions
- SSIS Data Flow task providing poor performance when using a Where Clause
- How can I share the same primary key across two tables?
- Partition by syntax
- Is it possible to use user defined table type inside another user defined table type in sql
- spring batch: efficient way to query results of a stored procedure within a tasklet
- Add an overall average row to Report Builder report
Source:
stackoverflow.com