在T-SQL中,可以使用GROUP BY子句按照不同的元素进行分组。下面是一个包含代码示例的解决方法:
假设有一个名为"employees"的表,其中包含以下列:employee_id、first_name、last_name和department。
SELECT department, COUNT(*) as total_employees
FROM employees
GROUP BY department;
SELECT first_name, last_name, AVG(salary) as average_salary
FROM employees
GROUP BY first_name, last_name;
SELECT department, job_title, COUNT(*) as total_employees
FROM employees
GROUP BY department, job_title;
SELECT department, MAX(salary) as max_salary, MIN(salary) as min_salary
FROM employees
GROUP BY department;
上述代码示例演示了如何使用GROUP BY子句按照不同的元素进行T-SQL分组。您可以根据自己的需求调整和扩展这些示例。