-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample_sql_queries.sql
More file actions
60 lines (45 loc) · 1.76 KB
/
Copy pathsample_sql_queries.sql
File metadata and controls
60 lines (45 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Databricks notebook source
-- MAGIC %md
-- MAGIC
-- MAGIC # Access Database Sample Queries
-- MAGIC
-- MAGIC This notebook contains some of the work to demonstrate moving an Access database to Databricks.
-- MAGIC
-- MAGIC We save the Access tables as CSVs and then import them into "Data" on Databricks. This notebook implements some of the queries in the original database.
-- MAGIC
-- MAGIC ### Example - Displaying a Table
-- MAGIC
-- MAGIC We display an arbitrary table from the database
-- COMMAND ----------
SELECT * FROM default.anamorphs;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC
-- MAGIC ### Example - "Find duplicates for journalsTemp" Query
-- MAGIC
-- MAGIC Migrating the find duplicates query from the Access database
-- COMMAND ----------
SELECT first(journals_temp.journal_abbreviation) AS journal_abbreviation, count(journals_temp.journal_abbreviation) AS NumberOfDups
FROM journals_temp
GROUP BY journals_temp.journal_abbreviation
HAVING (((count(journals_temp.journal_abbreviation))>1));
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Example - "SBML_geo_lookup" Query
-- MAGIC
-- MAGIC Migrating the SBML_geo_lookup query from the Access database
-- COMMAND ----------
SELECT hp_locality_links.fk_host_pathogen_id, localities.geographical_abbreviation AS Locality, localities.country
FROM localities INNER JOIN hp_locality_links ON localities.pk_location_id=hp_locality_links.fk_location_id
ORDER BY Locality, fk_host_pathogen_id;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC
-- MAGIC ### Example - "hostsbytaxa" Query
-- MAGIC
-- MAGIC Migrating the hostsbytaxa query from the Access database
-- COMMAND ----------
SELECT DISTINCT hosts.fk_higher_taxa_id, hosts.host_genus
FROM hosts
WHERE (((hosts.host_genus)<>"*Unspecified"))
ORDER BY hosts.host_genus;