I am trying to get a metric of my database of 'relationships' that are found in less than 10% of 'sources'. I have successfully created a table that has every relationship, as well as the corresponding percentage of sources each relationship is found in. Below is my code:
use rt_database;
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
#Used the code above to ensure ONLY_FULL_GROUP_BY mode is deactivated for my grouping
SELECT observations.`Relationship ID`,
ROUND((COUNT(statements.`Source ID`) /
(SELECT COUNT(sources.`Source ID`) from sources)),3) * 100
AS "Ubiquity Percentage"
FROM statements
JOIN observations ON statements.`Old Observation ID` = observations.`Old Obs ID`
GROUP BY observations.`Relationship ID`
#HAVING "Ubiquity Percentage" < 10
#The line above is what I thought would successfully limit my table to only relationships less than 10%
ORDER BY observations.`Relationship ID`
;
The code above works perfectly in getting me a complete table with each relationship and it's corresponding percentage. However, when I uncomment the HAVING line, no changes are made to the table. And if I edit the HAVING line to say HAVING "Ubiquity Percentage" > 10
, then the table output is completely empty. Below is a screenshot of the current results I'm getting:
Would love some help. Thank you!