April 6, 2016 at 4:27 pm
Hello,
I'm relatively new to SQL, having been primarily a SAS user in the past. I've having a hard time figuring out how to calculate the percent difference between two rows in a dataset. Here's a mockup:
Academic Years2009-20102010-20112011-20122012-2013sort column
Number Applied1002003004001
Number Accepted4003002001002
I am having a hard time getting the numbers to line up correctly beneath each column heading. Regardless, every column has values.
I need to calculate Number Accepted/Number Applied * 100 for all of these columns. I'm fairly certain a lag or lead function needs to be involved. Please point me in the right direction.
Thank you.
April 6, 2016 at 5:58 pm
https://technet.microsoft.com/en-us/library/hh231256%28v=sql.110%29.aspx
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 6, 2016 at 7:07 pm
The sample data doesn't make much sense... how a school could accept more people than applicants is a big weird, but anyway...
CREATE TABLE Applications(
AcadYr INT,
Accepted INT,
Applied INT);
GO
INSERT INTO Applications(AcadYr,Accepted,Applied)
VALUES (2010,100,400),
(2011,200,300),
(2012,300,200),
(2013,400,100);
SELECT AcadYr
, Applied
, Accepted
, Accepted * 1.0 / Applied AS Rate
FROM Applications;
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply