Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION calculate_network(INTEGER,INTEGER)
- RETURNS void AS
- $$
- WITH RECURSIVE all_friends AS
- (
- SELECT befreundetmit,freundvon,freundschaftsgrad FROM istbefreundetmit
- UNION
- SELECT af.befreundetmit,f.freundvon,af.freundschaftsgrad
- FROM all_friends af join istbefreundetmit f
- ON af.freundvon = f.befreundetmit
- )
- SELECT DISTINCT count(*)
- FROM all_friends
- WHERE freundvon = $1 AND freundschaftsgrad > $2 AND befreundetmit != $1;
- UPDATE freunde SET anzahl = (SELECT DISTINCT count(*)
- FROM all_friends
- WHERE freundvon = $1 AND freundschaftsgrad > $2 AND befreundetmit != $1)
- WHERE freundid = $1;
- $$
- language 'sql';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement