mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
* Added some media for incoming demos on SQL Graph database * Added the file README.md and the first demo of the session SQL Server 2017 Graph Database that I have done at SQL Saturday Parma 2017 #sqlsat675 * Fixed a bug in SQL text visualization * Deleted some Unicode characters * Update file README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md added the demo "Build a sample recommendation system using SQL Graph" * Added the file sqlsat675 40 Recommendation system.sql that contains source code of the demo "Build a sample recommendation system using SQL Graph" * Update README.md * Added the file sqlsat675 30 Many-to-many relationships.sql * Delete folder sql-saturday-675-parma-italy * Add folder recommendation-system * Rename files * Update README.md * Update README.md * Update media file related to SQL Graph demos * Used function JSON_VALUE instead of OPENJSON to extract the first language of a Person * Update README.md * Update README.md * Update README.md * Update README.md
77 lines
1.8 KiB
Transact-SQL
77 lines
1.8 KiB
Transact-SQL
------------------------------------------------------------------------
|
|
-- Event: SQL Saturday #675 Parma, November 18 2017 -
|
|
-- http://www.sqlsaturday.com/675/EventHome.aspx -
|
|
-- Session: SQL Server 2017 Graph Database -
|
|
-- Demo: Demo1: Using the MATCH clause -
|
|
-- Author: Sergio Govoni -
|
|
-- Notes: -- -
|
|
------------------------------------------------------------------------
|
|
|
|
USE [WideWorldImporters];
|
|
GO
|
|
|
|
|
|
SELECT * FROM Edges.Friends;
|
|
|
|
-- List of all guys that speak finnish with friends
|
|
-- Pattern: Node > Relationship > Node
|
|
SELECT
|
|
P1.FullName
|
|
,P1.[Language]
|
|
,Friends_Number = COUNT(*)
|
|
FROM
|
|
Nodes.Person AS P1
|
|
,Edges.Friends AS Friends
|
|
,Nodes.Person AS P2
|
|
WHERE
|
|
MATCH(P1-(Friends)->P2)
|
|
AND (P1.[Language] = 'Finnish')
|
|
GROUP BY
|
|
P1.FullName, P1.[Language]
|
|
ORDER BY
|
|
Friends_Number DESC, P1.[Language];
|
|
GO
|
|
|
|
|
|
|
|
|
|
-- List of the top 5 people who have friends that speak Greek
|
|
-- in the first and second connections
|
|
SELECT
|
|
TOP 5
|
|
P1.FullName
|
|
,P1.[Language]
|
|
,GreekFriends = COUNT(*)
|
|
FROM
|
|
Nodes.Person AS P1
|
|
,Edges.Friends AS F1
|
|
,Nodes.Person AS P2
|
|
,Edges.Friends AS F2
|
|
,Nodes.Person AS P3
|
|
WHERE
|
|
MATCH(P1-(F1)-> P2-(F2)-> P3)
|
|
AND ((P2.[Language] = 'Greek') OR (P3.[Language] = 'Greek'))
|
|
GROUP BY
|
|
P1.FullName, P1.[Language]
|
|
ORDER BY
|
|
GreekFriends DESC, P1.[Language];
|
|
GO
|
|
|
|
|
|
-- People who have common friends that speak Croatian
|
|
SELECT
|
|
P1.FullName
|
|
,P2.FullName
|
|
,P2.[Language]
|
|
--,P3.FullName
|
|
FROM
|
|
Nodes.Person AS P1
|
|
,Edges.Friends AS F1
|
|
,Nodes.Person AS P2
|
|
,Edges.Friends AS F2
|
|
,Nodes.Person AS P3
|
|
WHERE
|
|
MATCH(P1-(F1)-> P2 <-(F2)-P3)
|
|
AND (P2.[Language] = 'Croatian')
|
|
AND (P1.$node_id <> P3.$node_id);
|
|
GO |