From a277a83b5415d5abc56625fd56d8f043cd77062f Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 10 Dec 2015 07:41:18 +0100 Subject: [PATCH] add usersnet_narrowfriend view --- sql/sql.d/075-users-network.sql | 14 ++++++++++++++ sql/sql.d/910-usernet_devel.sql | 2 ++ 2 files changed, 16 insertions(+) diff --git a/sql/sql.d/075-users-network.sql b/sql/sql.d/075-users-network.sql index cf108c0..a371ec5 100644 --- a/sql/sql.d/075-users-network.sql +++ b/sql/sql.d/075-users-network.sql @@ -23,6 +23,20 @@ CREATE INDEX #PFX#usersnet_owner_idx ON #PFX#usersnet (owner); CREATE INDEX #PFX#usersnet_target_idx ON #PFX#usersnet (target); CREATE UNIQUE INDEX #PFX#usersnet_owner_target_idx ON #PFX#usersnet (owner, target); +DROP VIEW #PFX#usersnet_widefriend; +CREATE VIEW #PFX#usersnet_widefriend + AS SELECT un.owner, ur.target, ur.friend, count(*) as count + FROM #PFX#usersnet AS un, #PFX#usersnet AS ur + WHERE un.target = ur.owner AND un.friend >= 4 -- 'un' is, at least, our friend + GROUP BY un.owner, ur.target, ur.friend; + +DROP VIEW #PFX#usersnet_narrowfriend; +CREATE VIEW #PFX#usersnet_narrowfriend + AS SELECT un.owner, ur.target, ur.friend, count(*) as count + FROM #PFX#usersnet AS un, #PFX#usersnet AS ur + WHERE un.target = ur.owner AND un.friend >= 5 -- 'un' is, at least, our friend + GROUP BY un.owner, ur.target, ur.friend; + DROP VIEW #PFX#usersnet_wideskill; CREATE VIEW #PFX#usersnet_wideskill AS SELECT un.owner, ur.target, SUM(ur.skill * un.trust) / SUM(un.trust) as skill, count(*) as count diff --git a/sql/sql.d/910-usernet_devel.sql b/sql/sql.d/910-usernet_devel.sql index d082220..9efb9f9 100644 --- a/sql/sql.d/910-usernet_devel.sql +++ b/sql/sql.d/910-usernet_devel.sql @@ -69,3 +69,5 @@ SELECT un.owner, ur.target, SUM(ur.skill * un.trust) AS num, SUM(un.trust) AS de SELECT us.login, pa.* FROM #PFX#usersnet_party pa, #PFX#users as us WHERE pa.target = us.code AND pa.owner = 10101; +SELECT * FROM #PFX#usersnet_widefriend ORDER BY owner, target, friend; +SELECT * FROM #PFX#usersnet_narrowfriend ORDER BY owner, target, friend; -- 2.17.1