Skip to content

Commit

Permalink
Merge branch 'oracle-livelabs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martygubar authored Apr 30, 2024
2 parents da35b4e + 06b0e8f commit ba7a7c9
Show file tree
Hide file tree
Showing 201 changed files with 490 additions and 465 deletions.
23 changes: 13 additions & 10 deletions json/mongodb-api/dbactions/dbactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ In this lab, you will:
![database name](./images/database-name.png " ")


7. On the database page, choose __Database Actions__.
7. On the database page, choose __View all database actions__ in the __Database Actions__ menu.

![choose database actions from the menu](./images/dbactions-button.png " ")

Expand All @@ -76,12 +76,14 @@ In this lab, you will:
* SQL - allows you to work with a relational, **SQL-based** view of your data
* Charts - generate charts over data in Autonomous Database

All of these tools are under the __Development__ section

![menu for database actions](./images/dbactions-menu.png " ")


## Task 2: JSON in Database Actions

1. You should be in the Database Actions panel. Click on the **JSON** card
1. You should be in the Database Actions panel. Click on the **JSON** tool in the Development tab.

![choose JSON](./images/dbactions-menu-json.png " ")

Expand Down Expand Up @@ -182,7 +184,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap

![back to dbactions](./images/back-to-dbactions.png " ")

Now we want to open SQL. Click on the SQL panel in Database Actions
Now we want to open SQL. Select __SQL__ in the Development section.

![dbactions menu](./images/dbactions-menu-sql.png " ")

Expand All @@ -200,7 +202,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap

```
<copy>
select * from emp
select * from emp;
</copy>
```
![simple select command](./images/select-star.png " ")
Expand All @@ -216,7 +218,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap

```
<copy>
select json_serialize(data) from emp
select json_serialize(data) from emp;
</copy>
```

Expand All @@ -233,7 +235,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap
select e.data.name,
e.data.job,
e.data.salary
from emp e
from emp e;
</copy>
```

Expand All @@ -246,7 +248,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap
select avg (e.data.salary),
e.data.job
from emp e
group by e.data.job
group by e.data.job;
</copy>
```

Expand Down Expand Up @@ -293,6 +295,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap
dataguide => dg
);
end;
/
</copy>
```

Expand All @@ -309,7 +312,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap
select sum("salary"),
"job"
from emp_view
group by "job"
group by "job";
</copy>
```

Expand Down Expand Up @@ -340,7 +343,7 @@ Now we're going to look at a SQL view of the same data, showing how you can swap
select sum("salary"),
"job"
from emp_view
group by "job"
group by "job";
</copy>
```
On the right Choose "Pie Chart" in the "Chart type" drop-down. You can also select the "3D" option if you like. Click "Create" when done.
Expand All @@ -361,4 +364,4 @@ You may now proceed to the next lab to clean up your lab environment.

- **Author** - Roger Ford, Principal Product Manager
- **Contributors** - Kamryn Vinson, Andres Quintana
- **Last Updated By/Date** - Hermann Baer, June 2023
- **Last Updated By/Date** - Hermann Baer, April 2024
Binary file modified json/mongodb-api/dbactions/images/dbactions-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified json/mongodb-api/dbactions/images/dbactions-menu-charts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified json/mongodb-api/dbactions/images/dbactions-menu-json.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified json/mongodb-api/dbactions/images/dbactions-menu-sql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified json/mongodb-api/dbactions/images/dbactions-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions json/mongodb-api/install/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ Copy **ONE** of the following *curl* commands and paste it to the command or ter

```
<copy>
curl https://downloads.mongodb.com/compass/mongosh-1.9.1-darwin-x64.zip -o mongosh.zip
curl https://downloads.mongodb.com/compass/mongosh-2.2.4-darwin-x64.zip -o mongosh.zip
</copy>
```

2. For **Mac with Apple chip**:

```
<copy>
curl https://downloads.mongodb.com/compass/mongosh-1.9.1-darwin-arm64.zip -o mongosh.zip
curl https://downloads.mongodb.com/compass/mongosh-2.2.4-darwin-arm64.zip -o mongosh.zip
</copy>
```

3. For **Windows**:

```
<copy>
curl https://downloads.mongodb.com/compass/mongosh-1.9.1-win32-x64.zip -o mongosh.zip
curl https://downloads.mongodb.com/compass/mongosh-2.2.4-win32-x64.zip -o mongosh.zip
</copy>
```

Expand Down Expand Up @@ -132,4 +132,4 @@ You may now **proceed to the next lab**.

- **Author** - Roger Ford, Principal Product Manager, Oracle Database
- **Contributors** - Kamryn Vinson, Andres Quintana
- **Last Updated By/Date** - Hermann Baer, June 2023
- **Last Updated By/Date** - Hermann Baer, April 2024
14 changes: 4 additions & 10 deletions json/mongodb-api/mongoshell/mongoshell.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,10 @@ You should now be in Mongo Shell. This is a command-line utility to interact wit

```
<copy>
db.emp.insertOne(
{ "name":"Smith", "job": "Programmer", "salary": 60000, "email" : "smith@example.com" }
)
</copy>
```

```
<copy>
db.emp.insertOne(
db.emp.insertMany([
{ "name":"Smith", "job": "Programmer", "salary": 60000, "email" : "smith@example.com" },
{ "name":"Miller", "job": "Programmer", "salary": 70000 }
]
)
</copy>
```
Expand Down Expand Up @@ -201,4 +195,4 @@ You may now proceed to the next lab.

- **Author** - Roger Ford, Principal Product Manager
- **Contributors** - Kamryn Vinson, Andres Quintana
- **Last Updated By/Date** - Hermann Baer, June 2023
- **Last Updated By/Date** - Hermann Baer, April 2024
Binary file modified json/mongodb-api/provision/images/configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified json/mongodb-api/provision/images/workload-type2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 12 additions & 9 deletions json/mongodb-api/provision/provision.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In this lab, you will:

<if type="freetier">

2. If you are using a Free Trial or Always Free account, and you want to use Always Free Resources, you need to be in a region where Always Free Resources are available. You can see your current default **Region** in the top, right hand corner of the page.
2. If you are using a Free Trial or Always Free account, and you want to use Always Free Resources, you need to be in the home region of the tenancy. Always Free Resources are only available in the home regions. You can see your current default **Region** in the top, right hand corner of the page.

![Select region on the far upper-right corner of the page.](./images/region.png " ")

Expand Down Expand Up @@ -87,16 +87,15 @@ In this lab, you will:

4. Choose a workload type: Select the workload type for your database from the choices:

- __JSON__ - For this lab, choose __JSON__ as the workload type.
- __JSON__ - For this lab, choose __JSON__ as the workload type. Note that the MongoDB API is also available on Autonomous Transaction Processing and Autonomous Data Warehouse. However, Autonomous JSON database was purposely build, designed, and priced for JSON and document store workloads.

![Choose a workload type.](./images/workload-type2.png " ")

5. Choose a deployment type: Select the deployment type for your database from the choices:

- __Shared Infrastructure__ - For this lab, choose __Shared Infrastructure__ as the deployment type.
- __Dedicated Infrastructure__ - Alternatively, you could have chosen Dedicated Infrastructure as the deployment type.
- __Serverless__ - For this lab, choose __Serverless__ as the deployment type. (Autonomous JSON Database is only available on Serverless)

![Choose a deployment type.](./images/deployment-type.png " ")
![Choose a deployment type.](./images/workload-type2.png " ")

6. Configure the database:

Expand All @@ -107,12 +106,14 @@ In this lab, you will:
- __Always Free__ - For this lab, we recommend you leave Always Free unchecked.
</if>
- __Choose database version__ - Select 19c from the database version. Note: This lab should work on 21c AJD database as well.
- __OCPU count__ - Number of OCPUs for your service. For this lab, leave the default __1 OCPU__. If you choose an Always Free database, it comes with 1 OCPU.
- __Storage (TB)__ - Select your storage capacity in terabytes. For this lab, leave the default __1 TB__ of storage. If you choose an Always Free database, it comes with 20 GB of storage.
- __Auto Scaling__ - For this lab, keep auto scaling enabled, to allow the system to automatically use up to three times more CPU and IO resources to meet workload demand.
- __ECPU count__ - Number of ECPUs for your service. For this lab, leave the default __2 ECPU__. If you choose an Always Free database, it comes with preconfigured and fixed cpu capabilities.
- __Storage__ - Select your storage capacity in gigabytes. For this lab you can reduce the storage to the minimum of __20 GB__ of storage. If you choose an Always Free database, it comes with 20 GB of storage by default.
- __Auto Scaling__ - For this lab, keep auto scaling enabled, to allow the system to automatically use up to three times more CPU and IO resources to meet workload demand. (While this will not happen as part of the workshop, we don't know what else you are going to experiment with.)

*Note: You cannot scale up/down an Always Free autonomous database.*

If you are planning to use this autonomous database solely for the purpose of this workshop, you can reduce the backup retention also to the minimum of __1 day__.

![Choose the remaining parameters.](./images/configuration.png " ")

7. Create administrator credentials:
Expand All @@ -137,6 +138,8 @@ In this lab, you will:

You can then click "Add My IP Address" to allow access from your current IP address. You should avoid any VPN or proxy server access which may mask or change your actual IP address.

If you are behind a proxy setup and have issues with access from your local IP address, you can set the CIDR block access to 0.0.0.0/0, which allows access from **everywhere**. This is not recommended for systems used in any production configuration, but sufficient for a workshop.

![add your IP address](./images/network-access.png " ")

9. Choose a license type:
Expand Down Expand Up @@ -187,4 +190,4 @@ You may now **proceed to the next lab**.

- **Author** - Roger Ford, Principal Product Manager, Oracle Database
- **Contributors** - Kamryn Vinson, Andres Quintana
- **Last Updated By/Date** - Hermann Baer, June 2023
- **Last Updated By/Date** - Hermann Baer, April 2024
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# Analyze movie sales data
# Analyze the Movie Sales Data

## Introduction
In this lab, use Oracle analytic SQL to gain a better understanding of customers.
In this lab, you use Oracle analytic SQL to gain a better understanding of the customers.

Estimated Time: 5 minutes

### Objectives

- Understand how to use SQL Worksheet

- Bin customers by recency, frequency and monetary metrics

- Understand how to use the SQL Worksheet
- Group customers by recency, frequency and monetary metrics

### Prerequisites
- This lab requires completion of Labs 1 and 2 in the Contents menu on the left.

- This lab requires the completion of **Labs 1** and **Lab 2** in the **Contents** menu on the left.

## Task 1: Navigate to the SQL Worksheet
1. From the Data Load tool, navigate to the SQL Worksheet by clicking the top-left hamburger menu, navigate to **Development**, and then select **SQL**.

![Go to SQL worksheet](images/goto-sql.png " ")
1. From the Data Load tool, navigate to the SQL Worksheet. Click the **Selector** menu. In the **Development** section, click **SQL**.

2. Learn more about the SQL Worksheet features using the help tips or simply click the **X** on the top left of a tip to dismiss it. You will run queries by entering your commands in the worksheet. You can use the shortcuts [Control-Enter] or [Command-Enter] to run the command and view the Query Result (tabular format). Clear your worksheet by clicking the trash:
![Go to SQL worksheet](images/goto-sql.png =60%x*)

![Go to SQL worksheet](images/sql-worksheet.png " ")
The SQL Worksheet is displayed.

You are now ready to start analyzing MovieStream's performance using SQL.
![The SQL worksheet is displayed](images/sql-worksheet.png " ")

2. Learn more about the SQL Worksheet features using the tooltips when you hover over an icon. You will run queries by entering your commands in the worksheet. Click the **Run Statement** icon to run the command and view the output in the **Query Result** tab in tabular format. Click the **Run Script** icon to run a script and display the output in the **Script Output** tab in text format. You can clear your worksheet by clicking the trash icon.

## Task 2: Explore sales data
![Go to SQL worksheet](images/run-query.png " ")

1. Let's use a very simple query to look at sales by customer education level.
You are now ready to start analyzing MovieStream's performance using SQL.

## Task 2: Explore the Sales Data

1. Let's use a very simple query to look at sales by customer education level. Copy the following code and paste it in your SQL Worksheet, and then click the **Run Statement** icon in the toolbar.

```
<copy>select
Expand All @@ -43,36 +46,33 @@ You are now ready to start analyzing MovieStream's performance using SQL.
</copy>
```

Copy this SQL statement into the worksheet, and press the **Run command** button to start the query. This returns a result similar to the following:
This returns a result similar to the following:

![sales by education level](images/sales-by-education-level.png " ")


As you can see, most sales are to customers with a high school education, and the fewest sales are to customers with a masters degree. It is interesting that MovieStream has more sales to customers with a doctorate degree than customers with a masters degree!


## Task 3: Finding our most important customers
## Task 3: Finding our Most Important Customers

### Overview
Let's pivot and look at customer behavior by utilizing an RFM analysis. RFM is a very commonly used method for analyzing customer value. It is often used in general customer marketing, direct marketing, and retail sectors.

In the following steps, the scripts will build a SQL query to identify:
Let's pivot and look at customer behavior by utilizing an **RFM** analysis. RFM is a very commonly used method for analyzing customer value. It is often used in general customer marketing, direct marketing, and retail sectors.

- Recency: when was the last time the customer accessed the site?
In the following steps, the scripts will build a SQL query to identify:

- Frequency: what is the level of activity for that customer on the site?
- **Recency:** when was the last time the customer accessed the site?

- Monetary Value: how much money has the customer spent?
- **Frequency:** what is the level of activity for that customer on the site?

Customers will be categorized into 5 buckets measured (using the NTILE function) in increasing importance. For example, an RFM combined score of 551 indicates that the customer is in the highest tier of customers in terms of recent visits (R=5) and activity on the site (F=5), however the customer is in the lowest tier in terms of spend (M=1). Perhaps this is a customer that performs research on the site, but then decides to buy movies elsewhere!
- **Monetary Value:** how much money has the customer spent?

1. Binning customers based on behavior
Customers will be categorized into 5 buckets measured (using the **`NTILE`** function) in increasing importance. For example, an **RFM** combined score of **551** indicates that the customer is in the highest tier of customers in terms of recent visits (**R=5**) and activity on the site (**F=5**); however the customer is in the lowest tier in terms of spend (**M=1**). Perhaps this is a customer that performs research on the site, but then decides to buy movies elsewhere!

Use the following query to segment customer behavior into 5 distinct bins based on the recency, frequency and monetary metrics:
1. Let's bin customers based on their behavior. Copy the following query and paste it in your SQL Worksheet, and then click the **Run Statement** icon in the toolbar. Use the query to segment customer behavior into **5 distinct bins** based on the **recency**, **frequency**, and **monetary** metrics.

```
<copy>SELECT
cust_id,
cust_id,
NTILE (5) OVER (ORDER BY max(day_ID)) AS rfm_recency,
NTILE (5) OVER (ORDER BY count(1)) AS rfm_frequency,
NTILE (5) OVER (ORDER BY SUM(actual_price)) AS rfm_monetary
Expand All @@ -81,19 +81,16 @@ Customers will be categorized into 5 buckets measured (using the NTILE function)
ORDER BY cust_id
FETCH FIRST 10 ROWS ONLY;</copy>
```
Below is a snapshot of the result (and your result may differ):

![binned customers by sales, last visit and frequency](images/t4-bin-rfm.png " ")
Below is a snapshot of the result (your result may differ).

![binned customers by sales, last visit and frequency](images/t4-bin-rfm.png =65%x*)

The rfm\_* columns in the report shows the "bin" values based on the 5 quintiles described above.

For more information about using the `NTILE` function, see [the SQL documentation](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/NTILE.html#GUID-FAD7A986-AEBD-4A03-B0D2-F7F2148BA5E9).

For more information about using the `NTILE` function, see the [SQL Language Reference](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/NTILE.html#GUID-FAD7A986-AEBD-4A03-B0D2-F7F2148BA5E9) documentation.

2. Add customer information to the RFM query

Now we use the **`WITH`** clause to create an RFM query and then join that to attributes coming from the CUSTOMER table. In addition, the query will focus on important customers (based on spend) that are at risk:
2. Add customer information to the RFM query. Now we use the **`WITH`** clause to create an RFM query and then join that to attributes coming from the **CUSTOMER** table. In addition, the query will focus on important customers (based on spend) that are at risk. Copy the following query and paste it in your SQL Worksheet, and then click the **Run Statement** icon in the toolbar.

```
<copy>WITH rfm AS (
Expand Down Expand Up @@ -121,18 +118,17 @@ Customers will be categorized into 5 buckets measured (using the NTILE function)
AND r.rfm_recency = 1
ORDER BY r.rfm_monetary desc, r.rfm_recency desc;</copy>
```
The result only shows customers who historically had significant spend (equal to 5) but have not visited the site recently (equal to 1). MovieStream does not want to lose these important customers!

The result only shows customers who historically had significant spend (equal to 5) but have not visited the site recently (equal to 1). MovieStream does not want to lose these important customers!

![RFM query](images/t4-rfm.png " ")


## Recap
We accomplished alot in just 15 minutes!
We accomplished a lot in just 15 minutes!

* Deployed an Autonomous Database instance that is optimized for data warehousing workloads
* Used Autonomous Database tools to load object storage sources
* Use advanced SQL to uncover issues and possibilities

* Used Autonomous Database tools to load data from object storage sources
* Used advanced SQL to uncover issues and possibilities

## Learn more

Expand All @@ -141,5 +137,7 @@ We accomplished alot in just 15 minutes!

## **Acknowledgements**

- **Authors** - Marty Gubar, Oracle Autonomous Database Product Management
- **Last Updated By/Date** - Katherine Wardhana, User Assistance Developer, February 2024
- **Authors:**
* Marty Gubar, Oracle Autonomous Database Product Management
* Lauran K. Serhal, Consulting User Assistance Developer
- **Last Updated By/Date:** Lauran K. Serhal, April 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ba7a7c9

Please sign in to comment.