Minion Blog
http://anisoft.cloudvps.bg/blog/
SELECT * FROM Departments |
SELECT Name FROM Departments |
SELECT CONCAT(FirstName, ' ' , LastName) FullName FROM Employees |
SELECT DISTINCT Salary FROM Employees |
SELECT * FROM Employees e WHERE JobTitle = 'Sales Representative' |
SELECT FirstName, LastName FROM Employees WHERE LastName like '%ei%' |
SELECT Salary FROM Employees e WHERE Salary BETWEEN 20000 AND 30000 |
SELECT FirstName, LastName FROM Employees WHERE Salary IN (25000, 14000, 12500, 23600) |
SELECT FirstName, LastName, Salary FROM Employees WHERE Salary > 50000 ORDER BY Salary DESC |
SELECT TOP 5 FirstName, LastName, Salary FROM Employees WHERE Salary > 50000 ORDER BY Salary DESC |
SELECT FirstName, LastName, AddressText FROM Employees e JOIN Addresses a ON e.AddressID = a.AddressID |
or
SELECT FirstName, LastName, AddressText FROM Employees e, Addresses a WHERE e.AddressID = a.AddressID |
SELECT CONCAT(e.FirstName, ' ' , e.LastName) AS FullName, CONCAT(m.FirstName, ' ' , m.LastName) ManagerFullName, a.AddressText FROM Employees e JOIN Employees m on e.ManagerID = m.EmployeeID JOIN Addresses a on e.AddressID = a.AddressID |
SELECT CONCAT(FirstName, ' ' , LastName) AS FullName, Salary FROM Employees WHERE Salary = ( SELECT MIN (Salary) FROM Employees) |
We have one join and where for salary equal to min salary by departments
SELECT CONCAT(FirstName, ' ' , LastName) AS FullName, Salary, d. Name FROM Employees e JOIN Departments d ON d.DepartmentID = e.DepartmentID WHERE Salary = ( SELECT MIN (Salary) FROM Employees WHERE DepartmentID = e.DepartmentID) order by d. Name |
SELECT AVG (Salary) [Avarage Salary] FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID WHERE d. Name = 'Sales' |
SELECT COUNT (*) [ Count Employees] FROM Employees e WHERE ManagerID IS NOT NULL |
When we have aggregate function and colum we must group records by column name.
SELECT d. Name [Department], AVG (Salary) [Avarage Salary] FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID GROUP BY d. Name |
When we have grouping and must filter by something we use HAVING.
SELECT CONCAT(e.FirstName, ' ' , e.LastName) ManagerName, COUNT (*) [ Count Employees] FROM Employees e JOIN Employees em ON em.ManagerID = e.EmployeeID GROUP BY e.FirstName, e.LastName HAVING COUNT (*) = 5 |
or
we can create temporary table it nested select and make where on it
SELECT * FROM ( SELECT CONCAT(e.FirstName, ' ' , e.LastName) ManagerName, COUNT (*) [ Count Employees] FROM Employees e JOIN Employees em ON em.ManagerID = e.EmployeeID GROUP BY e.FirstName, e.LastName) AS Managers WHERE Managers.[ Count Employees] = 5 |
We must use if statement in sql this is (case -> then -> else).
SELECT CONCAT(e.FirstName, ' ' , e.LastName) AS FullName, CASE WHEN CONCAT(m.FirstName, ' ' , m.LastName) <> ' ' THEN CONCAT(m.FirstName, ' ' , m.LastName) ELSE 'no manager' END AS ManagerFullName FROM Employees e LEFT JOIN Employees m on e.ManagerID = m.EmployeeID |
SELECT CONCAT(e.FirstName, ' ' , e.LastName) ManagerName FROM Employees e WHERE LEN(e.LastName) = 5 |
The format must be given with numbers.
SELECT CONCAT( CONVERT ( varchar , GETDATE(), 104), ' ' , CONVERT ( varchar , GETDATE(), 114)) |
He calls himself a Code Hunter.
He constantly leads battles with his new and old enemies the CODES.
His final aim is to become Master Developer.
He uses hidden weapons against evil Bugs and crafty Codes to win this hard battle.
The most powerful weapon is his Motivation to keep on and to WIN in the End.
Variant 1: JavaScript Class Generator
Example:
Input Fields: x – number, y – number, isMale – bool, name – string
Variant 2: JavaScript Class Generator
Play Game Ice Racing