SlideShare a Scribd company logo
MySQLWithout
the SQL - Oh My!
Dave Stokes
@stoker
david.stokes@oracle.com
Elephantdolphin.blogger.com
opensourcedba.wordpress.com
Relational Databases
2
Relational Databases
● Data Integrity
○ Normalization
○ constraints (foreign keys, ...)
● Atomicity, Consistency, Isolation, Durability
○ ACID compliant
○ transactions
● SQL
○ powerful query language 3
NoSQL or Document Store
4
NoSQL or Document Store
● Schemaless
○ No schema design, no normalization, no foreign keys, no data types, …
○ Very quick initial development
● Flexible data structure
○ Embedded arrays or objects
○ Valid solution when natural data can not be modelized optimally into a
relational model
○ Objects persistence without the use of any ORM - *mapping
object-oriented*
● JSON
● close to frontend
● native in JS
● easy to learn
5
How DBAs see data as opposed to how Developers see data
{
"GNP" : 249704,
"Name" : "Belgium",
"government" : {
"GovernmentForm" :
"Constitutional Monarchy, Federation",
"HeadOfState" : "Philippe I"
},
"_id" : "BEL",
"IndepYear" : 1830,
"demographics" : {
"Population" : 10239000,
"LifeExpectancy" : 77.8000030517578
},
"geography" : {
"Region" : "Western Europe",
"SurfaceArea" : 30518,
"Continent" : "Europe"
}
}
6
What if there was a way to provide both SQL
and NoSQL on one stable platform that has
proven stability on well know technology
with a large Community and a diverse
ecosystem ?
With the MySQL Document
Store SQL is now optional!
7
A Solution for all
Developers:
★ schemaless
★ rapid prototyping &
simpler APIs
★ document model
★ transactions
Operations:
★ performance
management/visibility
★ robust replication, backup,
restore
★ comprehensive tooling
ecosystem
★ simpler application schema
upgrades
8
Business Owner:
★ don't lose my data ==
ACID trx
★ capture all my data =
extensible/schemaless
★ product on schedule/time
to market = rapid
development
Built on the MySQL JSON Data type and Proven MySQL Server Technology 9
★ Provides a schema flexible JSON Document Store
★ No SQL required
★ No need to define all possible attributes, tables, etc.
★ Uses new X DevAPI
★ Can leverage generated column to extract JSON values into materialized
columns that can be indexed for fast SQL searches.
★ Document can be ~1GB
○ It's a column in a row of a table
★ Allows use of modern programming styles
○ No more embedded strings of SQL in your code
○ Easy to read
★ Also works with relational Tables
★ Proven MySQL Technology
★ Connectors for
○ C++, Java, .Net, Node.js, Python, PHP
○ working with Communities to help them supporting it too
★ New MySQL Shell
○ Command Completion
○ Python, JavaScripts & SQL modes
○ Admin functions
○ New Util object
○ A new high-level session concept that can scale from single
MySQL Server to a multiple server environment
★ Non-blocking, asynchronous calls follow common language patterns
★ Supports CRUD operations
10
Starting using MySQL in few minutes 11
Shell info 12
For this example, I will use the well known restaurants collection:
We need to dump the data to a file and
we will use the MySQL Shell
with the Python interpreter to load the data.
Migration from MongoDB to MySQL Document Store
13
Dump and load using MySQL Shell & Python
This example is inspired by @datacharmer's work: https://www.slideshare.net/datacharmer/mysql-documentstore
$ mongo quiet eval 'DBQuery.shellBatchSize=30000;
db.restaurants.find().shellPrint()' 
| perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' > all_recs.json
14
15
16
Let’s query
Too many records to show here … let’s limit it!
17
More Examples!
18
Let’s add a selection criteria
>
db
.r
es
ta
> db.restaurants.find({"cuisine": "French",
"borough": { $not: /^Manhattan/} },
{"_id":0, "name": 1,"cuisine": 1, "borough": 1}).limit(2)
{ "borough" : "Queens", "cuisine" : "French",
"name" : "La Baraka Restaurant" }
{ "borough" : "Queens", "cuisine" : "French",
"name" : "Air France Lounge" } 19
Syntax is slightly
different than
MongoDB
20
CRUD Operations
21
Add a Document
22
Modify a Document
23
Remove a Document
24
Find a Document
25
MySQL Document Store Objects Summary
MySQL Document Store is Fully ACID Compliant 26
MySQL Document Store is Fully ACID Compliant 27
What about old SQL? The Hidden Part of the Iceberg 28
★ Native datatype (since 5.7.8)
★ JSON values are stored in MySQL tables using UTF8MB4
★ Conversion from "native" SQL types to JSON values
★ JSON manipulation functions (JSON_EXTRACT, JSON_KEYS,
JSON_SEARCH, JSON_TABLES, ...)
★ Generated/virtual columns
○ Indexing JSON data
○ Foreign Keys to JSON data
○ SQL Views to JSON data
JSON datatype is behind the scene
29
How Does It Work?? 30
What does a collection look like on the server ? 31
Every document has a unique identifier called the document ID,
which can be thought of as the equivalent
of a table´s primary key. The document ID value can be manually
assigned when adding a document.
If novalue is assigned, a document ID is generated and assigned
to the document automatically !
Use getDocumentId() or getDocumentIds() to get _ids(s)
_id
32
Mapping to SQL Examples
createCollection('mycollection')
CREATE TABLE `test`.`mycoll` (
doc JSON,
_id VARCHAR(32)
GENERATED ALWAYS AS (doc->>'$._id') STORED
PRIMARY KEY
) CHARSET utf8mb4;
mycollection.add({‘test’: 1234})
INSERT INTO `test`.`mycoll` (doc) VALUES (
JSON_OBJECT('_id','663807fe367ee6114e0e5458bdac28bf', 'test',1234));
33
More Mapping to SQL Examples
mycollection.find("test > 100")
SELECT doc
FROM `test`.`mycoll`
WHERE (JSON_EXTRACT(doc,'$.test') >100);
34
35
SQL and JSON Example
It's also possible to create indexes without using SQL syntax 36
SQL and JSON Example (2): validation 37
SQL and JSON Example (3): explain 38
SQL and JSON Example (3): explain 39
SQL and JSON Example (4): add index 40
SQL and JSON Example (4): add index 41
SQL and JSON Example (5): arrays 42
NoSQL as SQL 43
JSON_TABLE turns your
un-structured JSON data into a
temporary structured table!
NoSQL as SQL 44
This temporary structured table can
be treated like any other table --
LIMIT, WHERE, GROUP BY ...
45
More Sophisticated Analysis
Find the top 10 restaurants by grade for each cuisine 46
WITH cte1 AS (SELECT doc->>"$.name" AS 'name',
doc->>"$.cuisine" AS 'cuisine',
(SELECT AVG(score) FROM
JSON_TABLE(doc, "$.grades[*]"
COLUMNS (score INT PATH "$.score")) as r ) AS avg_score
FROM restaurants)
SELECT *, rank() OVER
(PARTITION BY cuisine ORDER BY avg_score) AS `rank`
FROM cte1
ORDER by `rank`, avg_score DESC limit 10;
This query uses a Common Table Expression (CTE) and a Windowing Function to rank the average
scores of each restaurant, by each cuisine
SQL and NoSQL 47
Show Results 48
JOINing tables 49
Conclusion: What Do I Gain?
50
This is the best of the two worlds in one product !
● Data integrity
● ACID Compliant
● Transactions
● SQL
● Schemaless
● flexible data structure
● easy to start (CRUD)
51
Thanks!
Contact info:
Dave Stokes
David.Stokes@Oracle.com
@Stoker
slideshare.net/davidmstokes
Elepantdolphin.blogger.com
opensourcedba.Wordpress.com
52

More Related Content

PPTX
Discover the Power of the NoSQL + SQL with MySQL
PDF
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
PPTX
MongoDB
PPTX
MongoDb and NoSQL
PPT
Introduction to MongoDB
PDF
How to search extracted data
ODP
MongoDB - javascript for your data
PPTX
Introduction to MongoDB
Discover the Power of the NoSQL + SQL with MySQL
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
MongoDB
MongoDb and NoSQL
Introduction to MongoDB
How to search extracted data
MongoDB - javascript for your data
Introduction to MongoDB

What's hot (20)

PDF
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
PDF
Memory management
PDF
Back to Basics 2017: Mí primera aplicación MongoDB
ODP
2011 Mongo FR - Indexing in MongoDB
PPTX
Back to Basics, webinar 2: La tua prima applicazione MongoDB
PPTX
MongoDB Shell Tips & Tricks
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
PPTX
Tag based sharding presentation
KEY
Introduction to MongoDB
PDF
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
PPTX
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
PDF
Mongo db
PDF
Hive jdbc
PPTX
Beyond the Basics 2: Aggregation Framework
PDF
PDF
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
PDF
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
PDF
Python Files
PDF
Latinoware
PDF
Hands On Spring Data
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
Memory management
Back to Basics 2017: Mí primera aplicación MongoDB
2011 Mongo FR - Indexing in MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
MongoDB Shell Tips & Tricks
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Tag based sharding presentation
Introduction to MongoDB
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
Mongo db
Hive jdbc
Beyond the Basics 2: Aggregation Framework
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Python Files
Latinoware
Hands On Spring Data
Ad

Similar to MySQL Without The SQL -- Oh My! PHP Detroit July 2018 (20)

PDF
MySQL without the SQL -- Cascadia PHP
PDF
MySQL Document Store -- SCaLE 17x Presentation
PDF
Open Source World June '21 -- JSON Within a Relational Database
PDF
Json within a relational database
PDF
MySQL Without the SQL -- Oh My!
PDF
Datacon LA - MySQL without the SQL - Oh my!
PPTX
Discover The Power of NoSQL + MySQL with MySQL
PPTX
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
PDF
MySQL Document Store - when SQL & NoSQL live together... in peace!
PPTX
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
ODP
MySQL Without the MySQL -- Oh My!
PPTX
Making MySQL Agile-ish
PDF
Oracle Code Event - MySQL JSON Document Store
PDF
MySQL NoSQL JSON JS Python "Document Store" demo
PDF
Python and MySQL 8.0 Document Store
PPTX
A Step by Step Introduction to the MySQL Document Store
PDF
MySQL 5.7 Tutorial Dutch PHP Conference 2015
PDF
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
PPTX
No sql for sql professionals
PDF
MySQL as a Document Store
MySQL without the SQL -- Cascadia PHP
MySQL Document Store -- SCaLE 17x Presentation
Open Source World June '21 -- JSON Within a Relational Database
Json within a relational database
MySQL Without the SQL -- Oh My!
Datacon LA - MySQL without the SQL - Oh my!
Discover The Power of NoSQL + MySQL with MySQL
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Document Store - when SQL & NoSQL live together... in peace!
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the MySQL -- Oh My!
Making MySQL Agile-ish
Oracle Code Event - MySQL JSON Document Store
MySQL NoSQL JSON JS Python "Document Store" demo
Python and MySQL 8.0 Document Store
A Step by Step Introduction to the MySQL Document Store
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
No sql for sql professionals
MySQL as a Document Store
Ad

More from Dave Stokes (20)

PDF
Database basics for new-ish developers -- All Things Open October 18th 2021
PDF
Php & my sql - how do pdo, mysq-li, and x devapi do what they do
PDF
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
PDF
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
PDF
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
PDF
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
PPTX
Validating JSON -- Percona Live 2021 presentation
PDF
Midwest PHP Presentation - New MSQL Features
PDF
Data Love Conference - Window Functions for Database Analytics
PPTX
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
PPTX
Confoo 2021 -- MySQL New Features
PPTX
Confoo 2021 - MySQL Indexes & Histograms
PDF
MySQL Replication Update - DEbconf 2020 presentation
PDF
MySQL 8.0 Operational Changes
PPTX
cPanel now supports MySQL 8.0 - My Top Seven Features
PDF
Confoo 202 - MySQL Group Replication and ReplicaSet
PPTX
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PDF
MySQL New Features -- Sunshine PHP 2020 Presentation
PPTX
MySQL 8.0 from December London Open Source Database Meetup
PPTX
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Database basics for new-ish developers -- All Things Open October 18th 2021
Php & my sql - how do pdo, mysq-li, and x devapi do what they do
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Validating JSON -- Percona Live 2021 presentation
Midwest PHP Presentation - New MSQL Features
Data Love Conference - Window Functions for Database Analytics
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Confoo 2021 -- MySQL New Features
Confoo 2021 - MySQL Indexes & Histograms
MySQL Replication Update - DEbconf 2020 presentation
MySQL 8.0 Operational Changes
cPanel now supports MySQL 8.0 - My Top Seven Features
Confoo 202 - MySQL Group Replication and ReplicaSet
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
MySQL New Features -- Sunshine PHP 2020 Presentation
MySQL 8.0 from December London Open Source Database Meetup
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019

Recently uploaded (20)

PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Transform Your Business with a Software ERP System
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
history of c programming in notes for students .pptx
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
medical staffing services at VALiNTRY
PPTX
assetexplorer- product-overview - presentation
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
L1 - Introduction to python Backend.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Design an Analysis of Algorithms II-SECS-1021-03
Patient Appointment Booking in Odoo with online payment
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Transform Your Business with a Software ERP System
Reimagine Home Health with the Power of Agentic AI​
Salesforce Agentforce AI Implementation.pdf
history of c programming in notes for students .pptx
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
medical staffing services at VALiNTRY
assetexplorer- product-overview - presentation
Odoo Companies in India – Driving Business Transformation.pdf
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Oracle Fusion HCM Cloud Demo for Beginners
L1 - Introduction to python Backend.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

MySQL Without The SQL -- Oh My! PHP Detroit July 2018

  • 1. MySQLWithout the SQL - Oh My! Dave Stokes @stoker [email protected] Elephantdolphin.blogger.com opensourcedba.wordpress.com
  • 3. Relational Databases ● Data Integrity ○ Normalization ○ constraints (foreign keys, ...) ● Atomicity, Consistency, Isolation, Durability ○ ACID compliant ○ transactions ● SQL ○ powerful query language 3
  • 5. NoSQL or Document Store ● Schemaless ○ No schema design, no normalization, no foreign keys, no data types, … ○ Very quick initial development ● Flexible data structure ○ Embedded arrays or objects ○ Valid solution when natural data can not be modelized optimally into a relational model ○ Objects persistence without the use of any ORM - *mapping object-oriented* ● JSON ● close to frontend ● native in JS ● easy to learn 5
  • 6. How DBAs see data as opposed to how Developers see data { "GNP" : 249704, "Name" : "Belgium", "government" : { "GovernmentForm" : "Constitutional Monarchy, Federation", "HeadOfState" : "Philippe I" }, "_id" : "BEL", "IndepYear" : 1830, "demographics" : { "Population" : 10239000, "LifeExpectancy" : 77.8000030517578 }, "geography" : { "Region" : "Western Europe", "SurfaceArea" : 30518, "Continent" : "Europe" } } 6
  • 7. What if there was a way to provide both SQL and NoSQL on one stable platform that has proven stability on well know technology with a large Community and a diverse ecosystem ? With the MySQL Document Store SQL is now optional! 7
  • 8. A Solution for all Developers: ★ schemaless ★ rapid prototyping & simpler APIs ★ document model ★ transactions Operations: ★ performance management/visibility ★ robust replication, backup, restore ★ comprehensive tooling ecosystem ★ simpler application schema upgrades 8 Business Owner: ★ don't lose my data == ACID trx ★ capture all my data = extensible/schemaless ★ product on schedule/time to market = rapid development
  • 9. Built on the MySQL JSON Data type and Proven MySQL Server Technology 9 ★ Provides a schema flexible JSON Document Store ★ No SQL required ★ No need to define all possible attributes, tables, etc. ★ Uses new X DevAPI ★ Can leverage generated column to extract JSON values into materialized columns that can be indexed for fast SQL searches. ★ Document can be ~1GB ○ It's a column in a row of a table ★ Allows use of modern programming styles ○ No more embedded strings of SQL in your code ○ Easy to read ★ Also works with relational Tables ★ Proven MySQL Technology
  • 10. ★ Connectors for ○ C++, Java, .Net, Node.js, Python, PHP ○ working with Communities to help them supporting it too ★ New MySQL Shell ○ Command Completion ○ Python, JavaScripts & SQL modes ○ Admin functions ○ New Util object ○ A new high-level session concept that can scale from single MySQL Server to a multiple server environment ★ Non-blocking, asynchronous calls follow common language patterns ★ Supports CRUD operations 10
  • 11. Starting using MySQL in few minutes 11
  • 13. For this example, I will use the well known restaurants collection: We need to dump the data to a file and we will use the MySQL Shell with the Python interpreter to load the data. Migration from MongoDB to MySQL Document Store 13
  • 14. Dump and load using MySQL Shell & Python This example is inspired by @datacharmer's work: https://www.slideshare.net/datacharmer/mysql-documentstore $ mongo quiet eval 'DBQuery.shellBatchSize=30000; db.restaurants.find().shellPrint()' | perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' > all_recs.json 14
  • 15. 15
  • 16. 16 Let’s query Too many records to show here … let’s limit it!
  • 18. 18 Let’s add a selection criteria
  • 19. > db .r es ta > db.restaurants.find({"cuisine": "French", "borough": { $not: /^Manhattan/} }, {"_id":0, "name": 1,"cuisine": 1, "borough": 1}).limit(2) { "borough" : "Queens", "cuisine" : "French", "name" : "La Baraka Restaurant" } { "borough" : "Queens", "cuisine" : "French", "name" : "Air France Lounge" } 19 Syntax is slightly different than MongoDB
  • 25. 25 MySQL Document Store Objects Summary
  • 26. MySQL Document Store is Fully ACID Compliant 26
  • 27. MySQL Document Store is Fully ACID Compliant 27
  • 28. What about old SQL? The Hidden Part of the Iceberg 28
  • 29. ★ Native datatype (since 5.7.8) ★ JSON values are stored in MySQL tables using UTF8MB4 ★ Conversion from "native" SQL types to JSON values ★ JSON manipulation functions (JSON_EXTRACT, JSON_KEYS, JSON_SEARCH, JSON_TABLES, ...) ★ Generated/virtual columns ○ Indexing JSON data ○ Foreign Keys to JSON data ○ SQL Views to JSON data JSON datatype is behind the scene 29
  • 30. How Does It Work?? 30
  • 31. What does a collection look like on the server ? 31
  • 32. Every document has a unique identifier called the document ID, which can be thought of as the equivalent of a table´s primary key. The document ID value can be manually assigned when adding a document. If novalue is assigned, a document ID is generated and assigned to the document automatically ! Use getDocumentId() or getDocumentIds() to get _ids(s) _id 32
  • 33. Mapping to SQL Examples createCollection('mycollection') CREATE TABLE `test`.`mycoll` ( doc JSON, _id VARCHAR(32) GENERATED ALWAYS AS (doc->>'$._id') STORED PRIMARY KEY ) CHARSET utf8mb4; mycollection.add({‘test’: 1234}) INSERT INTO `test`.`mycoll` (doc) VALUES ( JSON_OBJECT('_id','663807fe367ee6114e0e5458bdac28bf', 'test',1234)); 33
  • 34. More Mapping to SQL Examples mycollection.find("test > 100") SELECT doc FROM `test`.`mycoll` WHERE (JSON_EXTRACT(doc,'$.test') >100); 34
  • 35. 35 SQL and JSON Example
  • 36. It's also possible to create indexes without using SQL syntax 36
  • 37. SQL and JSON Example (2): validation 37
  • 38. SQL and JSON Example (3): explain 38
  • 39. SQL and JSON Example (3): explain 39
  • 40. SQL and JSON Example (4): add index 40
  • 41. SQL and JSON Example (4): add index 41
  • 42. SQL and JSON Example (5): arrays 42
  • 43. NoSQL as SQL 43 JSON_TABLE turns your un-structured JSON data into a temporary structured table!
  • 44. NoSQL as SQL 44 This temporary structured table can be treated like any other table -- LIMIT, WHERE, GROUP BY ...
  • 46. Find the top 10 restaurants by grade for each cuisine 46 WITH cte1 AS (SELECT doc->>"$.name" AS 'name', doc->>"$.cuisine" AS 'cuisine', (SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]" COLUMNS (score INT PATH "$.score")) as r ) AS avg_score FROM restaurants) SELECT *, rank() OVER (PARTITION BY cuisine ORDER BY avg_score) AS `rank` FROM cte1 ORDER by `rank`, avg_score DESC limit 10; This query uses a Common Table Expression (CTE) and a Windowing Function to rank the average scores of each restaurant, by each cuisine
  • 50. Conclusion: What Do I Gain? 50
  • 51. This is the best of the two worlds in one product ! ● Data integrity ● ACID Compliant ● Transactions ● SQL ● Schemaless ● flexible data structure ● easy to start (CRUD) 51