Coding Musings

Trying to share some code ideas

logo

Oracle PL/SQL More Aggregation – Rank

Oracle PL/SQL Aggregation  – Rank

One of the more interesting aggregation functions is RANK.  After doing a standard SELECT and GROUP BY; you can then have SQL rank the results using an aggregated value from another column.

Let’s dive in and look at how RANK works and what can it do for us.

Oracle 12c Limit Rows Returned

Limit Rows Returned

Previous to Oracle 12c limit the number of rows returned usually meant encapsulating the query as a subquery.  It wasn’t particularly nice looking and was out of alignment with other relational database query languages.

MySQL uses the LIMIT operator and Microsoft T-SQL uses the TOP operator. In Oracle 12c, Oracle introduced the FETCH FIRST operator.  Let’s see how it works.

Oracle PL/SQL Subtotal Operators

Oracle PL/SQL Subtotal Operators

There are times when we need not just the total value for the column, but subtotal values depending on different column values.  Oracle supports subtotal operators through the three key operators they are CUBE, ROLLUP, and GROUPING SETS. Below are examples of each one and how best to use them.

Aggregation in Oracle PL/SQL

Aggregation in Oracle PL/SQL

Oracle 12 uses normal SQL statements when doing aggregation.  The standard rules for aggregating in SQL apply.  You need to group by all non aggregated columns and having clause will be evaluated after the group by operator.

Some examples of aggregation in Oracle PL/SQL are below.

Dropping Tables in Oracle PL/SQL

Dropping Tables

Below are some examples of how to create tables in Oracle 12. PL/SQL, for the most part PL/SQL follows standard SQL conventions.

R Markdown to WordPress

Posting an Rmd File to WordPress

Updated: 2021-10-02 for R version 4.1

There are four R packages you will need to be able to post an Rmd file to WordPress. Yes there are alternatives you can generate the HTML yourself and copy and paste things, but why would you want to do it?

Creating Tables in Oracle 12 PL/SQL

Creating Tables

Below are some examples of how to create tables in Oracle 12. PL/SQL. For the most part PL/SQL follows standard SQL conventions.  I will show how to create some tables and some of the more popular options when creating tables.

Testing for Unconnected Components in a Graph

Testing for Unconnected Components in an Undirected Graph

With a graph structure it is possible that parts of the graph will not be connected to each other.  An example of this would be with social networks, not all users are friends with other users.

The code will find the total number of connected components of the graph, or graph parts in an undirected graph.

See code below.

Finding an Exit from a Maze

Finding an Exit from a Maze using undirected graphs.

We can think of a maze as a rectangular grid of cells with paths between adjacent cells. If we want to find if there is a path from a given cell to a given exit from the maze, where the exit is represented by a cell, you can represent the maze as an undirected graph.

The nodes of the graph are cells of the maze, and two nodes are connected an undirected edge if they are adjacent and there is no wall between them. Therefore we can surmise we just need to see if a path, series of edges connecting the nodes, to determine if the two nodes are connected.

See code below.

Spark – Streaming Data

Spark – Streaming Data, Capturing and Querying

Today we will look at how to capture streaming data and perform some simple queries as the data is streamed. We will use the regular expressions library and the PySpak library.  The streaming data comes from a weather station that transmits different weather at different intervals.  We will need to find the correct data out of the stream and output the results.

Let’s get started.

Page 4 of 6

Powered by WordPress & Theme by Anders Norén