|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
The Ranking Function | |
I have a table with various products and associated metadata. I run this query:
SELECT r.ItemName , r.ItemType , RANK () OVER (ORDER BY r.Price desc) AS Ranking FROM dbo.Ranking AS r;How many products and which types are ranked with a "2" for the Ranking column in the result set? The DDL and DML are below: CREATE TABLE dbo.Ranking ( ItemID INT NOT NULL , ItemName VARCHAR(10) , ItemType VARCHAR(20) , Qty INT , Price int ) GO INSERT dbo.Ranking (ItemID, ItemName, ItemType, Qty, Price) VALUES (1, 'Dell', 'Laptop', 2, 500) , (2, 'HP', 'Laptop', 3, 800) , (3, 'Lenovo', 'Laptop', 4, 900) , (4, 'Samsung', 'Mobile', 5, 900) , (5, 'Apple', 'Mobile', 6, 1200) , (6, 'Apple', 'Watch', 2, 400) , (7, 'Samsung', 'Watch', 3, 500) , (8, 'Garmin', 'Watch', 4, 200) , (9, 'Rolex', 'Watch', 5, 1200) GO | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by Steve Jones - SSC Editor) |
Pizza Math (from a post on Twitter). I went to get a round 9 inch pizza the other day, but they had run out of those pans. They brought me two circular 5 inch pizzas. What does this mean for my hunger? Answer: I'm hungry. I get much less pizza than I expected. Explanation: While you might be tempted to say one should never eat pizza, that's certainly incorrect. This is a basic math question about the area of a circle. For a 9 inch pizza (circular), there are 254 sq. inches. A 5 inch pizza is only about 78.5 sq inches, so two of them are 157 sq inches, nearly 100 inches short. |
Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
SQL Server 2016 - Administration |
First responders kit - BlitzIndex question - Hello, hope someone can help, maybe a simple question so i am using the Blitzindex from Brent Ozar, and its great, but one question, with some of the findings being "Missing Index" or "Index phobia", it does say estimated impact or missing index request... I am looking for a way to find out "This would […] |
SQL Server 2016 - Development and T-SQL |
Quick SQL challenges for mid-experienced+ DBAs (and advanced T-SQLers) - (1) Sort rows with year column (smallint) and month column (char(3)) == Jan, Feb, Mar, etc. == correctly, without using CASE or other conditional expressions (the simpler the better). (2) Table "emp_training" has (emp_id int, training_id int, status char(1)) where status = F(fail)/P(pass). Each employee (emp_id) may pass a class only once but may fail […] |
Designing a table - Hi, I have this list of training courses: Course_Code|Description 1 |Health and Safety 2 |cusomter relations 3 |IT training 9 |None Thanks. I have this scenario: A worker may attend up to 4 training courses per year. I need to design a table "WorkersCourses" where I can enter multiple records per worker. This will need […] |
Which table design is better ? - Hi, I have a scenario where a worker can do multiple training courses each year (max 4). Is it better to create a table this way: WorkerID |Year |Courses Worker01 |2021 |CourseCode01 Worker01 |2022 |CourseCode01 Worker01 |2022 |CourseCode02 Worker01 |2022 |CourseCode03 Or this way: WorkerID |Year|course1 |Course2 |Course3 |Course4 Worker01 |2021|CourseCode01| | | […] |
CAST AS DATE Assistance - Can someone let me know why I'm not able to use CAST method to cast a field as date ;WITH numbering AS ( SELECT MontaguOwner, CurrentOpportunityStatus, LastDateStatusChanged, OpportunityName, rank() OVER (PARTITION BY MontaguOwner, CurrentOpportunityStatus ORDER BY LastDateStatusChanged DESC) AS rank, row_number() OVER (PARTITION BY MontaguOwner, CurrentOpportunityStatus ORDER BY LastDateStatusChanged DESC) AS row_number FROM enrorigination.opportunities_hv […] |
Put result of one query into another - Hi all! I have to do this 177 times more, and it must be possible to make it a bit more automatic. I have to deliver +200 sets of queries, whish tells that two values should be updated. When finished, it will be run by my Customer. First query; SELECT per_personal_id FROM dbo.personal WHERE […] |
Administration - SQL Server 2014 |
SQL Server 2014 Question - So I have inherited an older SQL 2014 Server and have been working on understanding what I need to migrate or can shutdown without affecting our current applications. There is only one DB i know for a fact that relates to a digital faxing server we use I have a collection of 6 Databases with […] |
SQL Server 2019 - Administration |
Drop database on Secondary Node from Primary for automatic restore job - hi all We've ventured into the world of AAG's as we have now moved across to SQL2019. We have a Primary node and two secondary nodes. We have a training database that is autoamtically created from the main production database. This was initially added to the AAG manually and syncs fine. What we are now […] |
SQL Server 2019 HA - Looking for a HA solution for SQL server for our branch offices. Current setup has our 3 offices running independent standalone servers with SQL server. No redundancy in place. My aim is to centralise the servers in 2 locations. Location A and B has one server each. Both running windows server vm and sql in […] |
SQL Server 2019 - Development |
Group by column over partition ordered by date - Hi Everyone. I need a script to get the first and second null value from some records grouped by a column and ordered by date. I need the 311888 and 123477 itinerary groups because they have the first and second LegSegment as null value ordered by CreationDate, something like: select * from Test group by […] |
Combine tables with SQL in power bi - Hello everyone, i hope everyone is fantastic!! I've done some SQL queries in power bi to get my data and do some ETL. I have 6 companies, therefore, 6 queries. Now i would like to append them, combine(?) them in order to have just one sales table. What would you think it would be my […] |
Removing UNION and getting the same result - Hi, I need to update my sql script and remove the UNION but get the same result - Current result from script using Union - DDL- For Accounts and bp_table1 /****** Object: Table [dbo].[bp_Account] Script Date: 04/07/2022 10:48:17 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[bp_Account]( [bp_id] […] |
Employee Hierarchy Recursive CTE Different Top Level Directors Overtime - Hi, I have looked at some examples of Employee > Manager Hierarchy using Recursive CTE. The issue I have is the Top of Chain i.e. the Chairman there was different Chairman's over a period of time for example: Final Results I require If you look at EmpId 129 Rafael Nadal he left at the time Jeff […] |
SQL Azure - Administration |
Deploying a standalone Azure VM running SQL Server into an availability zone - If i deploy a standalone Azure VM running SQL Server into an availavility zone; what will this achieve? Will i get two load balanced copies of the instance running from VM's out of two data centers in the zone with the data being synced? I think that is what the documentation is suggesting, but I […] |
Design Ideas and Questions |
Multiple Fact Tables - Please assist? I would like to do a data model of the tables here: https://developers.google.com/doubleclick-advertisers/dtv2/reference/match-tables Any idea how i would go about to break this down and build a decent data model/links to tables? |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |