The document outlines SQL commands for creating a database and tables for students, courses, and instructors, including their attributes and relationships. It includes various SQL operations such as inserting, selecting, updating, and deleting records, as well as aggregate functions and views. Additionally, it demonstrates the use of Common Table Expressions (CTEs) to calculate average salaries by department.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
SENTENCIAS_BASICAS_SQL
The document outlines SQL commands for creating a database and tables for students, courses, and instructors, including their attributes and relationships. It includes various SQL operations such as inserting, selecting, updating, and deleting records, as well as aggregate functions and views. Additionally, it demonstrates the use of Common Table Expressions (CTEs) to calculate average salaries by department.
10. SELECT name AS nombre, date AS fecha FROM cursos;
11. UPDATE CURSOS SET FIRSTNAME=’Carolina’ WHERE FIRSTNAME=’Julian’
12. DELETE * FROM CURSOS
WHERE CURSEID=1;
13. SELECT * FROM INSTRUCTORS
WHERE INSTRUCTORID IN (2,5,7)
14. SELECT * FROM INSTRUCTORS
WHERE SALARY BETWEEN 5000 AND 7000
15. SELECT * FROM STUDENTS
WHERE LASTNAME LIKE ‘%Z’
16. SELECT NAME, LASTNAME FROM STUDENTS
WHERE AGE=20
17. SELECT FIRSTNAME, LASTNAME FROM STUDENTS
WHERE LASTNAME LIKE ‘%O%’
18. SELECT * FROM INSTRUCTORS
WHERE SALARY > 50000 AND FIRSTNAME LIKE ‘J%’
19. SELECT *FROM STUDENTS
WHERE FIRSTNAME IS NOT NULL
20. SELECT COURSEID, COUNT(STUDENTID)
FROM STUDENT_COURSE GROUP BY COURSEID HAVING COUNT (STUDENTID)>1
21. SELECT sum(SALARY) AS TOTALSALARY
FROM INSTRUCTORS 22. SELECT min(AGE) AS MINAGE FROM STUDENTES 23. SELECT AGE, CASE WHEN AGE BETWEEN 18 AND 20 THEN ‘TEAMA’ ELSE ‘TEAMB’ END FROM STUDENTS GROUP BY AGE
24. SELECT courses.id AS 'id', courses.name AS 'name',
courses.teacher_id AS 'teacher_id', teachers.name AS 'teacher_name' FROM courses INNER JOIN teachers ON courses.teacher_id=teachers.id;
VISTAS:
1. CREATE OR REPLACE VIEW VW_STUDENTS AS
SELECT STUDENT_ID, FIRSTNAME, LASTNAME FROM STUDENTS;
CTE (Common Table Expressions):
1. WITH AverageSalaries AS ( SELECT d.DepartmentName, AVG(e.Salary) AS AvgSalary FROM Employees e JOIN Departments d ON e.DepartmentID=d.DepartmentID GROUP BY d.DepartmentName )