Oracle Community

The social network for Oracle people

R Language & esProc to Implement SQL Join and Distinct etc. Functions

Every SQL users know that one has to finish composing all SQL codes and then run them all at one time, resulting in a poor ability for interactctive data analytics. However, the simple and easy-to-understand query syntax of SQL is always welcomed by programmers. As powerful computation and analysis tools, R language and esProc are surely need to offer the similar query syntax. In the last SQL basic functions article, we have discuss implement basic SQL functions like retrieve data of the entire table, where, order, group & sum. Let’s talk more today.

The example data is from 2 tables of the classical Northwind database:

Orders table with the main fields: OrderID, EmployeeID, OrderDate, Freight, CustomerID

Customer table with the main fields: CustomerID, CompanyName

Join:  Perform left join on Orders table and Customers table by CustomerID.

SQL Solution:

Select * from Orders left join Customers on Orders.CustomerID =Customers.CustomerID

esProc solution:

=join@1(A1:CustomerID:Orders, B1:CustomerID:Customers)

R solution:

merge(A1,B1,by.x="CustomerID",by.y="CustomerID",all.x=TRUE)

Comments: The join of SQL equals to join of esProc or the merge of R. Similarly, the left join of SQL equals to join@1 of esProc, or merge(...all.x=TRUE) of R. Obviously, esProc is more alike SQL in the respects of both the syntax conventions and the literal meanings. 

Distinct: Remove the duplicate CustomerID

SQL solution: select distinct CustomerID from Orders

R solution: unique(B2$CustomerID)

esProc solution: =B2.id(CustomerID)

Comments: The keywords of the two solutions respectively differ to that of SQL. However, their usages are basically the same to that of SQL. In which, R is the typical function style, and esProc is the typical object style.

Like: Search for the record with Island in ShipName

SQL solution: select * from Orders where ShipName like '%Island%'

R solution: subset(A1,grepl("Island",ShipName,ignore.case = TRUE))

esProc solution: =A1.select(like@c(ShipName ,"*Island*"))

Comments: R supports several means to match, including the regular expressions, and is more powerful than esProc in this respect. The usages of esProc are more close to that of SQL, and fit for those who are familiar with SQL.

When come to complex data calculation, SQL is replaceable in some aspects actually. Just as you see from above comparison, esProc has a coding style more close to that of SQL. 

R is more resourceful in details, ideal for the programmers and mathematicians. In addition, supporting the regular expressions and other functions makes R more open as a preferred analysis tool for programmers.  

Views: 22

Comment by daisy vennewald on October 18, 2012 at 7:13pm

Interesting, the esProc's join and distinct functions seams to be more convenient than SQL and R, and how about other functions?  I often use SQL for such calculating, and don't find other good tools now, and not sure if esProc can.

Comment by Jim King on October 18, 2012 at 7:54pm

Yeah, u are right, for people who want to save time and have no technical background. esProc can be more convenient application. Since you use SQL often, esProc should satisfy your needs. Let me tell you more about esProc.
esProc is a real OLAP tool, it does well in data analytics for structured data. The funcitons like retrieve data of entire table,  where condition, order, sort, group and sum etc. Since you use SQL, you should check this to know more about the differences about esProc: http://www.raqsoft.com/category/esproc/esproc-vs-sql

Comment

You need to be a member of Oracle Community to add comments!

Join Oracle Community

© 2013   Created by Eddie Awad.

Badges  |  Report an Issue  |  Terms of Service