It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am learning SQL and do some practice on the internet.
I cannot find the answer for the problem 4a and 4b on http://sqlzoo.net/2b.htm
The table's name is nobel and have 3 colums (yr, subject, winner)
The question is:
Show the years in which three prizes were given for Physics.
Show winners who have won more than once.
Thanks
This should do it for 4a:
SELECT yr
FROM nobel
WHERE subject = 'Physics'
GROUP BY yr
HAVING COUNT(*) = 3;
And for 4b:
SELECT winner
FROM nobel
GROUP BY winner
HAVING COUNT(*) > 1;
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How to get this payment?
employer_payment.payment = employer_salary.salary - employer_advance_payment.advance_payment
Please give me your suggestions on the question how I solve this problem?
you can use LEFT JOIN to be able to calculate the salary deducted by the advance_payment.
SELECT a.employerID,
a.salary - COALESCE(b.advance_payment, 0) payment
FROM employer_salary a
LEFT JOIN employer_advance_payment b
ON a.employerID = b.employerID
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am confused in selecting cars availability from my table as I want to list all the available Vehicles in a given branch
I have written this query but my brain stuck to carry on !?
SELECT MODEL, MAKE, START_DATE, TERMINATION_DATE
FROM VEHICLE_TYPE, VEHICLE, HIRE_AGREEMENT
WHERE VEHICLE_TYPE.VEHICLE_TYPE_ NUN = VEHICLE. VEHICLE_TYPE_NO
AND VEHICLE.VEHICLE_REG_NUM = HIRE_AGREEMENT.VEHICLE_REG_NO
AND ;
I believe from the start_date and termination_date I can get cars availability but HOW??
First, you should do a join instead of that old school stuff. Something like this is the best I can suggest given the information you have provided.
SELECT Vehicle.Model, Vehicle.Make, Hire_Agreement.Start_Date,
Hire_Agreement.termination_date FROM Vehicle
NATURAL INNER JOIN Hire_Agreement
WHERE
Hire_agreement.terminationDate >= Date() AND Hire_agreement.start_date <= Date();
This is all I can do considering you didnt give us your schema or flavor of SQL.
If I'm understanding correctly, something like this should work:
SELECT MODEL, MAKE, START_DATE, TERMINATION_DATE
FROM VEHICLE_TYPE, VEHICLE, HIRE_AGREEMENT
WHERE VEHICLE_TYPE.VEHICLE_TYPE_ NUN = VEHICLE. VEHICLE_TYPE_NO
AND VEHICLE.VEHICLE_REG_NUM = HIRE_AGREEMENT.VEHICLE_REG_NO
AND GETDATE() BETWEEN VEHICLE.START_DATE AND VEHICLE.TERMINATION_DATE
That should return all vehicles available as of the current date
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
In a SQL statement I am debugging, I found a - used in a way I don't recognize:
it appears in this SELECT statement between "Book_Balance" and "Participation_Lookups"
SELECT "LNIMPR"."Book_Balance" - "Participation_Lookups"."Participation Principal Assets" AS "C7"
FROM ...
What does the - do in the above context?
It is subtracting the two columns.
They must both be numeric values and in SQL to subtract you use the minus sign -.
If Book_balance is 100 and Participation Principal Assets is 25, then is it basically saying:
select 100 -25 as C7
from ...
This calculation is occurring for each row that is returned.
Numeric subtraction, as in 10 - 4 = 6
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I tried to do this:
SELECT SUM(SUBTOTAL as TODAYSALES) FROM dbo.SALESORD_HDR where ORDERDATE >=41187
But the browser throws an exception about the sum function saying 'SUM' is not a recognized built-in function name.
Any ideas?
Doing a
SELECT SUM(SUBTOTAL) as TODAYSALES FROM ...
would work a lot better.
Your syntax seems off. It should be SELECT SUM(SUBTOTAL) AS TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >= 41187
Aliases must be defined outside the expression they are targeting:
SELECT SUM(SUBTOTAL) as TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >=41187
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to add 2 hours to the result of getdate() in SQL SERVER. I know that I can add one day with:
select getdate() + 1
But how is this done when wanting to add on hours onto getdate()?
select dateadd(hour,2,getdate())
Select GETDATE() + (Convert(float,2)/Convert(float,24))
OR in other way
Select DateAdd(HH,2,Getdate())