T-SQL Demo – Abfragen & Beispiele
Diese Demo zeigt typische T-SQL-Abfragen inkl. erwarteter Ausgabe.
1. SELECT mit WHERE
SELECT Name, Age
FROM Employees
WHERE Age > 30;Erwartete Ausgabe:
+------------+-----+ | Name | Age | +------------+-----+ | Markus | 38 | | Stefanie | 41 | | Max | 33 | +------------+-----+
2. ORDER BY (Sortierung)
SELECT Name, Salary
FROM Employees
ORDER BY Salary DESC;Erwartete Ausgabe:
+------------+---------+ | Name | Salary | +------------+---------+ | Stefanie | 6500.00 | | Markus | 5200.00 | | Max | 4100.00 | | Mortiz | 3500.00 | +------------+---------+
3. GROUP BY + COUNT
SELECT Department, COUNT(*) AS EmployeeCount
FROM Employees
GROUP BY Department;Erwartete Ausgabe:
+-------------+----------------+ | Department | EmployeeCount | +-------------+----------------+ | IT | 3 | | HR | 1 | | Finance | 2 | +-------------+----------------+
4. Inner Join
SELECT e.Name, d.DepartmentName
FROM Employees e
INNER JOIN Departments d ON e.DepartmentId = d.Id;Erwartete Ausgabe:
+------------+----------------+ | Name | DepartmentName | +------------+----------------+ | Markus | IT | | Mortiz | IT | | Stefanie | Finance | | Max | IT | +------------+----------------+