Sentencias SQL
Sentencias SQL
Sentencias SQL
Your company is doing a survey of how many customers are registered in the states,
however, lacked to raise the data of the state of the 'Rio Grande do Sul'.
Then, you must show the names of all customers whose state is 'RS'.
The company will make an event celebrating the 20th anniversary of the market, and for
that we will make a great celebration in the city of Porto Alegre. We also invite all our
customers who are enrolled in this city.
Your job is in having the names and addresses of customers who live in 'Porto Alegre', to
deliver the invitations personally.
SELECT id,name FROM products WHERE price < '5' OR price > '100';
Materia: Taller de Base de Datos
Your job is to return the names of the products and providers whose category ID is 6.
Problema: Categories
When the data were migrated to the database, there was a small misunderstanding on the
DBA.
Your boss needs you to select the ID and the name of the products, whose categorie name
start with 'super'.
For this you must display only the highest and lowest price of the products table.
Then your job will display the name and amount of products of each category.
To help the industry that is doing this survey you should calculate and display the average
value of the price of the products.
OBS: Show the value with two numbers after the period.
To do this, select the code and the name of the movies in which the actors 'Marcelo Silva'
or 'Miguel Silva' acted and that the genre of the film is 'Action'
SELECT movies.id,movies.name
FROM movies FULL OUTER JOIN movies_actors ON movies.id =
movies_actors.id_movies
FULL OUTER JOIN actors ON actors.id = movies_actors.id_actors
FULL OUTER JOIN genres ON movies.id_genres = genres.id
WHERE (actors.name = 'Marcelo Silva' OR actors.name = 'Miguel Silva');
Materia: Taller de Base de Datos
Your job to help us is to select the ID and name of movies whose price is less than 2.00.
SELECT customers.name,rentals.rentals_date
FROM customers FULL OUTER JOIN rentals ON customers.id =
rentals.id_customers
WHERE rentals.rentals_date BETWEEN '2016-09-01' AND '2016-09-30';
Materia: Taller de Base de Datos
For you to help us select the name of all the cities where the rental company has clients.
But please do not repeat the name of the city.
Problema: No Rental
The video store company intends to do a promotion for customers who have not yet done
any rental.
Your job is to deliver us the ID and the name of the customers who have not done any
rental.
SELECT customers.id,customers.name
FROM customers LEFT JOIN locations ON customers.id =
locations.id_customers
WHERE locations.id_customers IS NULL;
Materia: Taller de Base de Datos
Your job is to display the name of the products and the name of the provider, for the
products supplied by the provider 'Ajax SA'
Your task is to display the name of the products, the name of the supplier and the name of
the category, for the products supplied by the supplier 'Sansul SA' and whose category
name is 'Imported'.
Your job is to display the name of the products, the name of the providers and the price, for
the products whose price is greater than 1000 and its category is' Super Luxury
Display the name of products whose amount are between 10 and 20 and whose name of
the supplier starts with the letter 'P'.
SELECT products.name
FROM products FULL OUTER JOIN providers ON products.id_providers =
providers.id
WHERE (products.amount BETWEEN 10 AND 20) AND providers.name LIKE
'P%';
Materia: Taller de Base de Datos
SELECT customers.name
FROM customers
RIGHT JOIN legal_person ON customers.id = legal_person.id_customers;
Materia: Taller de Base de Datos
To help the sales industry, display the product name and category name for products
whose amount is greater than 100 and the categorie ID is 1,2,3,6 or 9.
SELECT products.name,categories.name
FROM products INNER JOIN categories ON products.id_categories =
categories.id
WHERE products.amount > 100 AND products.id_categories IN (1,2,3,6,9);
Materia: Taller de Base de Datos
To do this you must display the number of distinct cities in the customers table
So your job now is to select all the CPFs of all the customers, and apply a mask on the
return of the data.
SELECT
CONCAT(SUBSTR(CPF,1,3),'.',SUBSTR(CPF,4,3),'.',SUBSTR(CPF,7,3),'-
',SUBSTR(CPF,10,2)) AS CPF
FROM natural_person;
Materia: Taller de Base de Datos
Problema: Lawyers
The manager of Mangojata Lawyers requested a report on the current lawyers.
The manager wants you to show him the name of the lawyer with the most clients, the one
with the fewest and the client average considering all lawyers.
OBS: Before presenting the average, show a field called Average to make the report more
readable. The average must be presented as an integer.
Problema: Contest
The Mars Technology University has Open Positions for researchers. However, the
computer responsible for processing the candidates' data is broken. You must present the
candidate list, containing the name and final score (with two decimal places of precision) of
each candidate. Remember to show the list ordered by score (highest first).
Avg=(math∗2)+(specific∗3)+(project_plan∗5)10
SELECT candidate.name,
ROUND(((score.math*2)+(score.specific*3)+(score.project_plan*5))/10,2)
AS avg from candidate FULL OUTER JOIN score ON candidate.id =
score.candidate_id
ORDER BY avg DESC;
Materia: Taller de Base de Datos
Problema: Payday
The Central Bank of Financing lost many registers after a server failure that happened last
October. The collection dates for the parcels where lost.
The bank requested your help to select the names and day of month in which each client
must pay theirs parcel.
Problema: League
The International Underground Excavation League is a success between alternative sports,
however the staff responsible for organizing the events doesn’t understand computers at
all, they only know how to dig and the sport rule set. As such, you were hired to solve the
League’s problem.
Select the three first placed with the initial phrase "Podium: " and select the last two, which
will be demoted to a lower league with the initial phrase “Demoted:".
Therefore, you should show the word 'Approved: ' alongisde the the name of a student
and the grade, for those who have been approved (grade ≥7).
As your first task, you must select every Richard from dimensions C875 and C774, together
with its existence probability (the famous factor N) with three decimal places of precision.
Remember that the N factor is calculated by multiplying the omega value by 1,618. The
data must be sorted by the least omega value
To help OMCNP, you must show the number of characters of each name sorted by
decreasing number of characters.
Problema: Passwords
You were hired to be the consultant for a company. Analyzing the database, you noticed
that the passwords are stored as text files and, as everyone knows, this is a terrible
security practice as they are not encrypted.
Therefore you must convert every password to the MD5 format. Show the client id, the
password before conversion and the new MD5
Problema: Taxes
You are going to the International Personal Tax meeting and your proposal is: every
individual with income higher than 3000 must pay a tax to the government, which is 10% of
his/her income.
Show the name and the tax value of each person who earns more than 3000, with two
decimal places of precision
Problema: Viruses
Viruses are evolving, but new research has proven that by switching some proteins the
vaccine becomes unbeatable. The protein H1(Hemagglutinin) when replaced by the X
protein (Xenomorphina) has interesting effects against almost every viral disease. Some
conspiracists say that after the vaccine’s discovery some strange 3 meters tall creatures
were found in the surroundings of the laboratories, but this is clearly a lie.
Therefore, you must replace every string “H1”( Hemagglutinin ) by 'X' ( Xenomorphina ).