Skip to content

Instantly share code, notes, and snippets.

@dzhlobo
Last active August 29, 2015 14:15
Show Gist options
  • Save dzhlobo/14909fb21677ced48942 to your computer and use it in GitHub Desktop.
Save dzhlobo/14909fb21677ced48942 to your computer and use it in GitHub Desktop.
SQL float comparison
MariaDB > SELECT id, summary_rating FROM companies ORDER BY summary_rating DESC;
+-------+----------------+
| id | summary_rating |
+-------+----------------+
| 75748 | 4.8 |
| 61769 | 4.76842 |
| 12475 | 4.59091 |
| 29849 | 4.54 |
+-------+----------------+
MariaDB > SELECT COUNT(*) FROM `companies` WHERE summary_rating >= 4.59091;
+----------+
| COUNT(*) |
+----------+
| 2 |
+----------+
MariaDB > SELECT COUNT(*) FROM `companies` WHERE summary_rating >= 4.59091 - 1e-6;
+----------+
| COUNT(*) |
+----------+
| 3 |
+----------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment