473,804 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused by OLAP functions

I want to do something that I'm sure is quite simple, but the DB2 SQL
Reference isn't too clear on this (lots of examples of things that I
don't want...)

Assume a table like this:
CREATE TABLE sales
(transactiondat e date,
productid int,
bookings int);

The first thing I want is a breakdown by productid of sales yesterday:

SELECT productid, sum(bookings)
FROM sales
WHERE transactiondate = current date - 1 days
GROUP BY productid;

So far, so easy. What I'm confused is how to get a breakdown by
productid of sales yesterday, and also show what percentage of sales
each productid contributed to the total -so I'd get a result set like
this:

PRODUCTID BKGS %AGE
1 4 50
2 2 25
3 2 25

I get the impression this would be by using PARTITION BY, but I can't
see quite how. (looking at an example on IBM's developerworks site, I
tried

SELECT productid, sum(bkgs) OVER (PARTITION BY productid) AS bkgsum,
(bkgs) / sum(bkgs) OVER (PARTITION BY product) AS percentage
FROM sales

but this doesn't work. Any pointers to a good syntax guide that isn't
vendor specific (if such a thing exists) that anyone can give me would
be greatly appreciated
Nov 12 '05 #1
2 3099
That should do it:
SELECT productid,
bkgs,
(bkgs * 100) / count(bkgs) over () AS "%AGE"
FROM (
SELECT productid, sum(bookings) bkgs
FROM sales
WHERE transactiondate = current date - 1 days
GROUP BY productid)
AS T;
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
sum of course.. not count
Serge Rielau wrote:
That should do it:
SELECT productid,
bkgs, (bkgs * 100) / sum(bkgs) over () AS "%AGE" FROM (
SELECT productid, sum(bookings) bkgs
FROM sales
WHERE transactiondate = current date - 1 days
GROUP BY productid)
AS T;

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3582
by: Will | last post by:
On the subject of Data Warehouses, Data Cubes & OLAP…. I would like to speak frankly about Data Warehouses, Data Cubes and OLAP (on-line analytical processing). Has it dawned on anyone else that these buzz words were created by some geek who decided to take a stab at marketing? Knowing that to the backwoods manager who knows little of technology that new innovative names for old concepts would help to sale their products. I mean...
0
3372
by: DD | last post by:
Hi Guys! Just would like to share with you my experiense in this matter. I was trying to evaluate how suitable Oracle OLAP for our applications. As probably you did, I have downloaded from OTN website OraJDeveloper and BI Beans, installed them and opened Cube Viewer ... no luck! Just did not work. After very long conversation(s) with Oracle Support I finally figured
0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ===================================
2
5229
by: Gadi Refaeli | last post by:
Hello All, We are currently considering DB purchases for a new system, we are looking at Cognos, Oracle, DB2 and Essbase. We came across some questions regarding Essbase and DB2 OLAP. 1. Are DB2 OLAP and Essbase are identical? 2. Does the standard Essbase SDK is provided with DB2 OLAP? 3. Does EIS is provided with DB2 OLAP? 4. Is there a way to get a "translation table" between DB2 OLAP and
3
5854
by: George Sakkis | last post by:
After a brief search, I didn't find any python package related to OLAP and pivot tables. Did I miss anything ? To be more precise, I'm not so interested in a full-blown OLAP server with an RDBMS backend, but rather a pythonic API for constructing datacubes in memory, slicing and dicing them, drilling down or up dimensions and exposing them in some suitable form to a presentation layer. I've hacked a first cut of a pivot table...
0
1685
by: YellowFin Announcements | last post by:
Yellowfin Reporting Announces Release 3 OLAP Connectivity New Features Including OLAP-to-Relational Drill Through Provide Customers with One Complete Web BI Tool for OLAP Analysis Yellowfin, today announced the availability of Yellowfin Release 3, the newest version of the leading query, reporting, and analysis tool for the web. Release 3 provides web access to all major relational and online analytical processing (OLAP) sources,...
0
1537
by: YellowFin | last post by:
Yellowfin Announces Release 3 OLAP Connectivity New Features Including OLAP-to-Relational Drill Through Provide Customers with One Complete Web BI Tool for OLAP Analysis Yellowfin, today announced the availability of Yellowfin Release 3, the newest version of the leading query, reporting, and analysis tool for the web. Release 3 provides web access to all major relational and online analytical processing (OLAP) sources, intelligent...
0
1298
by: lenygold via DBMonster.com | last post by:
Hi everybody. I am working on a query where SYSCAT.COLUMNS is part of the join and the output: colname colno generate_unique_val a 1 100000000000000 a 1 100000000000001 a 1 100000000000002 b 2 100000000000003 b 2 100000000000004
1
3170
by: sandeep.iitk | last post by:
Hi Friends, can anybody help me in rewriting below query with the help of OLAP functions. I never used OLAP functions , so need help in this regard. SELECT C.UNIT, C.DT from tab1 C where C.DT = (SELECT MAX(C_ED.DT) FROM tab1 C_ED WHERE C.UNIT = C_ED.UNIT AND C.ID = C_ED.ID AND C_ED.DT <= CURRENT DATE) Thanks in advance Sandy
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.