Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created August 6, 2011 01:17
Show Gist options
  • Save mohamedmansour/1128874 to your computer and use it in GitHub Desktop.
Save mohamedmansour/1128874 to your computer and use it in GitHub Desktop.
How similar is this user?
SELECT
@UserBit_50 as 'UserBit_50 (This Should not Be Null!)',
SUM(
(
convert( IFNULL(profilevalue_50, 0) , unsigned ) &
40988 /*@UserBit_50*/) > 0
) / (
SELECT COUNT(*) FROM se_profilevalues
) AS 'Avg Intersection'
FROM
se_profilevalues
WHERE
profilevalue_user_id != 1;
SELECT
BIT_COUNT(
IFNULL(
convert(Left.profilevalue_50, unsigned)
,0
) &
IFNULL(
convert(Right.profilevalue_50, unsigned)
,0
)
) / (
BIT_COUNT(
IFNULL(
convert(Left.profilevalue_50, unsigned)
,0
)
) +
BIT_COUNT(
IFNULL(
convert(Right.profilevalue_50, unsigned)
,0
)
)
)
FROM se_profilevalues AS 'Left'
INNER JOIN se_profilevalues AS 'Right'
ON Right.profilevalue_user_id = 2 /*Right User ID*/
WHERE
Left.profilevalue_user_id = 1 /*Left User ID*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment