dir.by  
Поиск >>

Компьютер, программы
→
Microsoft SQL (Database Query Language)
 Выбрать такие проекты, где количество задач в проекте больше или равно 3 (Используем group by, having count в SQL запросе) 
посмотрели 6361 раз
обновлено: 7 February 2019
Таблица Projects
Id
ProjectName
1
Project1
2
Project2
3
Project3
4
Project4
Таблица Tasks
Id
TaskName
Estimate
ProjectId
1
AAAAA for proj1
10
1
2
BBBBBB for proj1
6
1
3
CCCCC for proj1
2
1
4
EEEEEE for proj2
8
2
5
FFFFFF for proj2
9
2
6
IIIIIIIII for proj3
3
3
7
JJJJJJJ for proj3
18
3
8
KKKKKK for proj3
1
3
9
LLLLLLL for proj3
7
3
10
MMMMM for proj3
6
3
11
NNNNNN for proj4
2
4
Выбрать такие проекты, где количество задач в проекте больше или равно 3
  SQL запрос
select ProjectId, count(TaskName) as TaskCount from Tasks group by ProjectId having count(TaskName)>=3
Результат SQL запроса
ProjectId
TaskCount
1
3
3
5
 
 
Next topic →
inner join, left join, right join, outter join in a SQL query
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
SQL Examples
• Select projects where the number of tasks in the project is greater than or equal to 3 (Use group by, having count in a SQL query)
• inner join, left join, right join, outter join in a SQL query
• To make the values in the column non-repeating (add numbers to the duplicate names), use the update set in the SQL query
• How to use the SQL query to split a string into words using the delimiter in SQL Server ? Creating a Stored Function in SQL Server Management Studio
Simplify complex joins and subqueries in SQL
• Common Table Expressions (CTE) for simplify complex joins and subqueries in SQL
SQL Optimization
• Optimization, improvement of SQL queries

  Ваши вопросы присылайте по почте: info@dir.by