scinote-web/db/views/datatables_teams_v01.sql
2017-11-03 10:11:23 +01:00

13 lines
397 B
SQL

SELECT
teams.id AS id,
teams.name AS name,
user_teams.role AS role,
(
SELECT COUNT(*)
FROM user_teams
WHERE user_teams.team_id = teams.id
) AS members,
CASE WHEN teams.created_by_id = user_teams.user_id THEN false ELSE true END AS can_be_left,
user_teams.id AS user_team_id,
user_teams.user_id AS user_id
FROM teams INNER JOIN user_teams ON teams.id=user_teams.team_id