Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.82 KB | None | 0 0
  1. USE [UM3_kosuch]
  2. GO
  3.  
  4. /****** Object:  View [dbo].[serie_family]    Script Date: 17.10.2019 10:40:01 ******/
  5. SET ANSI_NULLS ON
  6. GO
  7.  
  8. SET QUOTED_IDENTIFIER ON
  9. GO
  10.  
  11. CREATE VIEW [dbo].[serie_family] (
  12.     ancestor_serie_id, descendant_serie_id, distance
  13. )AS
  14. WITH transitive AS (
  15.         SELECT parent_serie_id AS ancestor_serie_id, child_serie_id AS descendant_serie_id, 1 AS distance
  16.         FROM dbo.serie_parent_child
  17.     UNION ALL
  18.         SELECT spc.parent_serie_id AS ancestor_serie_id, t.descendant_serie_id, t.distance + 1
  19.         FROM dbo.serie_parent_child spc
  20.         JOIN transitive t ON t.ancestor_serie_id = spc.child_serie_id
  21. )
  22. SELECT ISNULL(ancestor_serie_id, '00000000-0000-0000-0000-000000000000'), ISNULL(descendant_serie_id, '00000000-0000-0000-0000-000000000000'), ISNULL(distance, 0) FROM transitive;
  23. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement