Hello Community,
I'm finding it hard to translate questions / requirements into SQL Query. I'm getting better at understanding SQL Code, but I still struggle translating requirements into code.
For example, if I gave you the following question would you know straight off the bat how to write sql code to get the answer:
Investigating trends and patterns in data often means looking at the data that makes up a specific area of data. Finding attributes of least (and most) profitable sales is an example of this kind of analysis. As a specific example, the sales director wants you to find all colors for cars sold for the least profitable 5 percent of sales.
The data / tables used to generate the code is as follows:
CREATE TABLE PrestigeCars.Data.SalesDetails (
SalesDetailsID INT IDENTITY
,SalesID INT NULL
,LineItemNumber TINYINT NULL
,StockID NVARCHAR(50) NULL
,SalePrice NUMERIC(18, 2) NULL
,LineItemDiscount NUMERIC(18, 2) NULL
) ON [PRIMARY]
GO
CREATE TABLE PrestigeCars.Data.Stock (
StockCode NVARCHAR(50) NULL CONSTRAINT DF_Stock_StockCode DEFAULT (NEWID())
,ModelID SMALLINT NULL
,Cost MONEY NULL
,RepairsCost MONEY NULL
,PartsCost MONEY NULL
,TransportInCost MONEY NULL
,IsRHD BIT NULL
,Color NVARCHAR(50) NULL
,BuyerComments NVARCHAR(4000) NULL
,DateBought DATE NULL
,TimeBought TIME NULL
) ON [PRIMARY]
GO
So, would the above be enough information for you generate the appropriate SQL script?
If so, how do you learn to interpret code straight off the bat like that.
I know the answer, but even when I look at the question again, I still struggle as to how to write the code for it?
Any guidance on how to obtain the expertise is greatly appreciated.