Question

In: Computer Science

*Note: someone else answered the question but queried for the average. I need the median NOT...

*Note: someone else answered the question but queried for the average. I need the median NOT the average. Thanks.

Hi, please help me create the following SQL query:

Create Table A with 1 column and 10 rows. The rows are filled with numbers : 1,2,3,4,5,6,7,8,9,10.

Create Table B with 1 column and 9 rows. The rows are filled with numbers: 1,2,3,4,5,6,7,8,9.

Write a single query that returns the median value of the 10 rows of TableA.

The same query should also work for Table B and return the median value of the 9 rows in Table B.

Expected Answers:

Median for Table A: 5.5

Median for Table B: 5

It would be really helpful if you could include screenshots. Thanks!

Solutions

Expert Solution

create table A(numbers Integer);
insert into A(numbers) values(1);

insert into A(numbers) values(2);

insert into A(numbers) values(3);

insert into A(numbers) values(4);

insert into A(numbers) values(5);

insert into A(numbers) values(6);

insert into A(numbers) values(7);

insert into A(numbers) values(8);

insert into A(numbers) values(9);

insert into A(numbers) values(10);

create table B(numbers Integer);

insert into B(numbers) values(1);

insert into B(numbers) values(2);

insert into B(numbers) values(3);

insert into B(numbers) values(4);

insert into B(numbers) values(5);

insert into B(numbers) values(6);

insert into B(numbers) values(7);

insert into B(numbers) values(8);

insert into B(numbers) values(9);

/*sql query for medain of table A*/

SELECT numbers as Median FROM
(SELECT a1.numbers, COUNT(a1.numbers) Rank
FROM A a1,A a2
WHERE a1.numbers< a2.numbers OR (a1.numbers=a2.numbers)
group by a1.numbers
order by a1.numbers desc) a3
WHERE Rank = (SELECT (COUNT(*)+1) DIV 2 FROM A);


/*sql query for medain of table B*/

SELECT numbers as Median FROM
(SELECT b1.numbers, COUNT(b1.numbers) Rank
FROM B b1,B b2
WHERE b1.numbers< b2.numbers OR (b1.numbers=b2.numbers)
group by b1.numbers
order by b1.numbers desc) b3
WHERE Rank = (SELECT (COUNT(*)+1) DIV 2 FROM B);



Related Solutions

I posted this question before and the person who answered it answered wrong.........please have someone else...
I posted this question before and the person who answered it answered wrong.........please have someone else try again The following information applies to the questions displayed below.] O’Brien Company manufactures and sells one product. The following information pertains to each of the company’s first three years of operations: Variable costs per unit: Manufacturing: Direct materials $28 Direct labor $15 Variable manufacturing overhead $5 Variable selling and administrative $3 Fixed costs per year: Fixed manufacturing overhead $580,000 Fixed selling and administrative...
***PLEASE ANSWER QUESTION AGAIN (SOMEONE ELSE)- FIRST ONE WAS ANSWERED INCORRECTLY The cash records of Jasmin...
***PLEASE ANSWER QUESTION AGAIN (SOMEONE ELSE)- FIRST ONE WAS ANSWERED INCORRECTLY The cash records of Jasmin Company show the following four situations: 1) The June 30 bank reconciliation indicated that deposits in transit total $2,110. During July the general ledger account Cash shows deposits of $23,620, but the bank statement indicates that only $23,400 in deposits were received during the month. 2) The June 30 bank reconciliation also reported outstanding checks of $1,250. During the month of July, Jasmin Company...
I please need assistance with the following question " of this question partially answered: Question: Digital...
I please need assistance with the following question " of this question partially answered: Question: Digital Solutions, Inc., manufactures two component parts for the television industry:  Voltag... What price should Digital Solutions charge for the New Voltage Regulator, and what next steps should Digital Solutions take regarding the New Voltage Regulator? 7) Provide a recommendation given the case facts and your analysis. 8) Pay attention to detail within your answers in terms of spelling, grammar, and formatting.   see the...
I only need question C answered, but I provided the rest of the worksheet to use...
I only need question C answered, but I provided the rest of the worksheet to use as reference in order to do so. Q1. Jamie wants to forecast the number of students who will enroll in operations management next semester in order to determine how many sections to schedule. He has accumulated the following enrollment data for the past six semesters: SEMESTER STUDENTS ENROLLED IN OM 1 270 2 310 3 250 4 290 5 370 6 410 a (2...
I just need question three answered. Here is the answer to question 2 and 1 if...
I just need question three answered. Here is the answer to question 2 and 1 if you need it. https://www.chegg.com/homework-help/questions-and-answers/need-question-2-answered-paste-link-answer-number-one-answered-another-chegg-tutor-https-w-q46591079?trackid=UL8zNe1z Suppose that two teams (for fun, let’s call them the Domestic Shorthairs and Cache Cows) play a series of games to determine a winner. In a best-of-three series, the games end as soon as one team has won two games. In a best-of-five series, the games end as soon as one team has won three games, and so on. Assume...
Note: These two problems are answered based on the question below. I believe the interest payments...
Note: These two problems are answered based on the question below. I believe the interest payments are (A)$100 and i believe the cash flows based on interest is (A)132.88 Consider a bond paying a coupon rate of 10% per year, compounded annually. Assume that the market interest rate (YTM or return on investments of like risk) is 15% per year. In other words you want a 15% return on the bond. The bond has three years until maturity. The par...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND 4. I HAVE FILLED OUT THE PERCENTAGE CHANGE FOR QUESTION 3, AND NEED HELP ON CALCULATING THE OPERATING, INVESTING, AND FINANCIAL SECTIONS. AS WELL AS, THE EQUATIONS FOR QUESTION 4. IF YOU CAN ANSWER QUESTIONS 3 & 4 I WILL AWARD CREDIT. Question 1: Common size for income statement Income Statement (Common Size) :                                                                  Consolidated Income Statement 2011 % 2010 % Revenue $19,176.1...
The whole question has been posted below, but I have answered some of them. I need...
The whole question has been posted below, but I have answered some of them. I need help with questions B, E, and F. I need the critical value in question B. I need the answers for the differences in question E. I need the answers for test statistics in F. Thank you. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Answer the one-way ANOVA questions using the data below. Use α = 0.01. 1 2 3 4 53 49 47 42 48 34 44 44 39 36...
This question was answered but I can't read the handwriting it was answered in, was hoping...
This question was answered but I can't read the handwriting it was answered in, was hoping I could get a readable version of the answer. Q 5-16: How did the TCJA alter the relative preferences in terms of organizational form? Illustrate this using a simple example where a business has pretax taxable income of $100 and operates: A. A c corporation subject to a 21% tax rate, that pays out all after-tax earnings as dividends, and in which the shareholders...
How are EHRs impacting the medical transcription job position? I need this question to be answered...
How are EHRs impacting the medical transcription job position? I need this question to be answered in essay form please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT