Help creating sql and concatenating column.
hello i have a table that looks like this
CREATE TABLE "TEST1"
( "TEST1_ROLE" VARCHAR2(100 BYTE),
"TEST1_VENDOR_NUMBER" VARCHAR2(100 BYTE)
it has this data
INSERT INTO "TEST1" (TEST1_ROLE, TEST1_VENDOR_NUMBER) VALUES ('student', '910241630')
INSERT INTO "TEST1" (TEST1_ROLE, TEST1_VENDOR_NUMBER) VALUES ('staff', '910241630')
INSERT INTO "TEST1" (TEST1_ROLE, TEST1_VENDOR_NUMBER) VALUES ('employee', '910241630')
i would like to create a query where i basically summarize based on vendor _number and i would end up with all the roles in one row
like this
910241630 student,staff, employee
I'm having a very difficult time trying to acomplish this can someone please give me a pointer on how i would acomplish this.
Hi,
That sounds like a job for the aggregate LISTAGG function:
SELECT test1_vendor_number
, LISTAGG (test1_role, ', ') WITHIN GROUP (ORDER BY test1_role) AS role_list
FROM test1
GROUP BY test1_vendor_number
This will produce a separate row of output for each distinct test1_vendor_number.
Similar Messages
-
OBIEE Group By on 2 facts and concatenated columns from different dimensions
Hi
I have a different kind of problem involving 2 fact tables with different dimensional attributes.
Fact 1 has Dim Attributes ( Cust,Facility )
Measure - Gross Amount
Fact2 has Dim attributes (Cust,Facility and Risk Group )
Measure : Exposure Amount
Since we have 2 facts with different dimensions,
to exclude the 'Risk Group' dimension column from the group by for the Fact1,
we set the 'Gross Amount' measure to total level (Risk Group Dimension ) in contents tab.
So the values from both the fact tables appears in the same report correctly.
But in the same report we have another requirement where the rating column from the customer dimension has to be concatenated with the ratings column in the facility dimension.
We have to concatenate customer.rating with the facility.rating and display it in the report.
when we just pull the individual columns from the dimensions into the report it works fine.
But when we try to concatenate the 2 columns and show it in the report,
the concatenated column does not appear in the select or the group by in the SQL Fact2.( Generated by OBIEE )
The other fact1 has the concatenated column in the select as well as the group by clause ( Generated by OBIEE )
As a result the report shows the concatenated values only for the results from the Fact1. But the results from Fact2 does not have the concatenated column values.
The report should look like the below:
Custor.Name, Customer.Id, Facility.Name, Facility.Id, Customer.Rating/Facility.Rating, Risk Group, Gross Amount, Exposure Amount
=========== ========= =========== ========= ======================== ========= =========== ===============
JPMC 123 GROSS 123 08/10 LNL 45,000 25,000
CLAIRE 456 NET 456 07/10 RNK 50,000 30,000
Thanks,
ChandraAs suggested you really want to move your none-aggregated fact attributes to a logical dimension (using the same physical table as the logical fact). Map this in the BMM layer as a snowflake, Place a hierarchy on this dimension with (at minimum) Total -> Detail levels, then on the other fact table you want to include in the report, set the content level on your other fact measures to the 'Total' level for your new logical Dim and it will allow them to be present in the same report.
-
Hi,
I have this table
declare @t_date table(cut_off datetime)
insert into @t_date
select '20140930'
union
select '20140716'
union
select '20140715'
union
select '20140714'
union
select '20140627'
union
select '20140625'
I need this result: Dates nearests to end of month
In the table on example, I need this output
2014-09-30
2014-07-16
2014-06-27
Can anyone help me?
Thanks a lot in advance.
declare @t_date table(cut_off datetime)
insert into @t_date
select '20140930' --this is OK cause eom
union
select '20140716' --this is OK cause is the nearest to eom(07)
union
select '20140715' --this is KO cause is not the nearest to eom(07)
union
select '20140714' --this is KO cause is not the nearest to eom(07)
union
select '20140627' --this is OK cause is the nearest to eom(06)
union
select '20140625' --this is KO cause is not the nearest to eom(06)Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. You have no keys! Learn how to follow ISO-11179 data element naming conventions and formatting rules.
Temporal data should use ISO-8601 formats. It is the only –- repeat, only -– format allowed in ANSI/ISO Standard SQL! Code should be in Standard SQL as much as possible and not local dialect. We would use the correct INSERT INTO syntax.
Oh, that silly “t_” is called a “tibble” and we laugh at it.
CREATE TABLE Foobar_Dates
(foobar_date DATE NOT NULL PRIMARY KEY);
INSERT INTO Foobar_Dates
VALUES
('2014-06-25'),
('2014-06-27'),
('2014-07-14'),
('2014-07-15'),
('2014-07-16'),
('2014-09-30'),
>> I need this result: for each month I need the date nearest to end of month <<
Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
Build good tools and re-use them!
The report period table gives a name to a range of dates that is common to the entire enterprise.
CREATE TABLE Month_Periods
(month_name CHAR(10) NOT NULL PRIMARY KEY
CHECK (month_name LIKE '[12][0-9][0-9][0-9]-[01][0-9]-00'),
month_start_date DATE NOT NULL,
month_end_date DATE NOT NULL,
CONSTRAINT date_ordering
CHECK (month_start_date < month_end_date),
etc);
These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
data format required by Standard SQL and it is language independent.
SELECT M.month_name, MAX(F.foobar_date),
OVER (PARTITION BY M.month_name)
FROM Foobar_Dates AS F,
Month_Periods AS M
WHERE F.foobar_date BETWEEN M.month_start_date AND M.month_end_date;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
I need help in creating a sql statement. For example lets say i have 3 tables one(key_id, os), two(key_id, type, desc), three(type, desc). I need to create a statement that is kind of like this but i need all rows in table one returned also.
select a.key_id, b.key_id, c.desc
from one a, two b, three c
where a.key_id = b.key_id and b.type = c.type;
Message was edited by:
user457357Or
michaels> with one as
(select 10 key_id from dual union all
select 20 from dual union all
select 30 from dual union all
select 40 from dual union all
select 50 from dual),
two as
(select 10 key_id,'aa' type from dual union all
select 20, 'aa' from dual union all
select 30, 'bb' from dual),
three as
(select 'aa' type ,'Artificial' des from dual union all
select 'bb','Bulk' from dual)
select a.*, b.key_id, c.des
from one a, two b, three c
where a.key_id = b.key_id(+)
and b.type = c.type(+)
KEY_ID KEY_ID_1 DES
10 10 Artificial
20 20 Artificial
30 30 Bulk
40
50 -
After Effects Help | Creating shapes and masks
This question was posted in response to the following article: http://helpx.adobe.com/after-effects/using/creating-shapes-masks.html
Hi Todd,
I don't think either approach accomplishes what I am trying to do. Just as when using a shape tool on an existing layer to create a mask, none of these approaches lets me alter a shape path after creating it, in terms of number of points, inner/outer radius and inner/outer roundness. Nor can I animate those characteristics.
The Help file creates the impression that you can copy/paste a Shape path from a Shape layer. If that were true, I could create a shape, copy/paste that path to a mask path, keyframe it, go back to the original shape layer, change its propertie and copy/paste that new shape path to the mask path at a different time, thus morphing from one shape to another. I don't see any way to do that.
Jeff -
Help creating search and results function for my site. Please help!
Hi guys,
I'm making an eCommerce/PayPal website for some products I'm selling. The website is currently built with PHP and HTML.
I want to add a search box so people can search for what the specifically want - then the results page will display a list of the products with links to the products' individual pages.
From what I understand this will almost certainly need to be database driven. My only problem is that I barely know where to start.
I've created a database on my host and have created dummy pages of how I want everything to look.
Each product will need 3-5 search terms attached to them.
Can someone please tell me where to begin and how difficult what I want to achieve will be?
Thank you and I hope to hear from you.
SMThe solution is database-driven only if the information about your products is in a database.
There are two approaches for a mySQL database, using the LIKE query and using MATCH AGAINST. These are SQL, not PHP, but the search results are processed by PHP.
There are plenty of tutorials on the web for these two methods. I prefer MATCH AGAINST, but it is a little bit more involved than LIKE. -
Hello everyone.
Well, here's another question... I have a 1.5T RAID 5 system for the Mac. On the PC, I put most of my CD / DVD movies/videos on the hard drives as a disc image. That way I have full access to my library without using my DVD drive.
I would like to do the same with Mac OS X. I have used the disk utility in the Utilities dir to create both a .dmg and a .cdr image of a DVD movie. I am unable to get any software play the image. Is this possible on the Mac? What do I need to do this, and how is it accomplished.
Thank you very much in advance.
Scott
Powermac G5 'Quad' Mac OS X (10.4.4)
Powermac G5 'Quad' Mac OS X (10.4.3)Kay:
Thanks a bunch for the information. I downloaded MTR, and it worked flawlessly! I can now use VLC or QT7+MP2 to view my DVD movies on the Mac from a file on my HDD.
Again, thank you for the information.
Scott
Powermac G5 'Quad' Mac OS X (10.4.3) -
Need help creating folders and files in Pathfinder
Hi, I have tried the Pathfinder forum but it's a ghost town over there. I don't know if this is a PF or Finder issue yet.
I've just installed Pathfinder 5.2.2 on an iMac running OS 10.5.8 at my new job.
The problem is I can open files and folders from within Pathfinder but I can't create any new files or folders from within Pathfinder, and I also can't drag anything from the drop stack to a new location either. I've made sure to set permissions for read/write on my Mac HD and on the PF application itself, and I've repaired my permissions, and also run Cocktail, restarted the mac, quit PF etc. Still nothing.
Anything that could point me in the right direction would be greatly appreciated.Hi Kappy,
When I try to move a folder or file, or create one, nothing happens at all. It's as if I never did anything. I am able to open files from within Pathfinder and navigate my Hard Drive, but I cannot create or delete files.
I posted on their forum, which is what they suggest. I've used Pathfinder for several years, I have no questions on the actual interface, but I wonder if there might be a permissions issue on this particular mac. -
I am not a dba just a hacker. To make my job easier I wanna run a .sql script from a shell. My sql selects an object_id and needs to use this value in subsequent lines. How do I do this in a myfile.sql? Here is the sql code:
SELECT r_object_id FROM dmi_vstamp_s WHERE i_application = ‘dm_docbase_config_ticket_crypto_key_init’;
DELETE FROM dmi_object_type WHERE r_object_id = '<returned r_object_id from above>';
Thanks in advance to all replies.
PhilIf the select query will return 1 value then use this:
DELETE FROM dmi_object_type
WHERE r_object_id =(SELECT r_object_id
FROM dmi_vstamp_s
WHERE i_application = ‘dm_docbase_config_ticket_crypto_key_init’);
If the select query will return more than 1 value then use this:
But this will delete all the rows returned by the select query!!
DELETE FROM dmi_object_type
WHERE r_object_id in (SELECT r_object_id
FROM dmi_vstamp_s
WHERE i_application = ‘dm_docbase_config_ticket_crypto_key_init’); -
SQL Loader, concatenating columns
Is it possible to concatenate several columns in a comma-delimited input file into one column in the database.
For example:
INPUT FILE:
1234,Description 1,Description2
DATABASE FILE (has 2 columns)
1.
Product Number (to be populated from '1234' in the input file)
2.
Description (to be populated from 'Description 1 Description 2' in the input file)
Please let me know how to do this. I was trying column object but it doesn't work.reference23 position(183:183) CHAR,
SOURCE position(183:194) CHAR NULLIF SOURCE=BLANKS,If you see the position for source column it should be 184 and not 183. I think it is a typo or you missed to spot it or I could be wrong. Just a thought
Regards
Raj
Message was edited by:
s.rajaram -
Need Help Creating Sound and Subtitle Setup Menu Scripts
Can someone point me to a tutorial or assist me with completing this menu:
http://www.aviewofyou.tv/mule/setupmenu.jpg
Basically, the user gets to pick their audio in stereo or 5.1 as well as whether or not the want to see the subtitles. So it would be cool to set it up so that that after they pick, say, Surround Sound, the script tells the DVD to play the 5.1 track and then places them on the Play Concert button. Same for stereo and subtitles.That's easier than you think, and it does not involve scripting.
Audio section:
Cllick on a stereo mix button in menu editor. Go to Inspector and chose Audio stream that contains Stereo mix. Set button target to Subtitles off button.
Do the same for 5.1 mix.
Subtitles section
Click on Subtitles off button. In the Inspector select an empty subtitles stream (32 for example) and set button target to Play Concert button
For Subtitles on button select the true subtitle stream and click "SHOW" box. Set button's target to Play Concert button.
That's all there is to it. -
Usage of SQL and SQLQuery Component Oracle BPM 10g
Hey Friends,
I have created SQl and SQL query catalog compoenents in Oracle BPM 10g, but unable to figure about how to use them in the BPM process. Do i need to create an automatic activity and make implemenatation as method and write java/pbl code there. Please suggest some solution with code snippet.
Thanks!!Having them cataloged constitutes most of the work you'll need to do. As you mention, the rest of the work is figuring out how you want to use them in a process.
As an example, if you wanted to have method that would return a list of customer ids you could create a method in a BPM Object:
listOfIds as String[]
for each element in
SELECT customerId
FROM customer
do
listOfIds[] = String(element.customerid)
end
// return the array with the valid values
return listOfIdsAfter adding this, you'll notice that there is an error flagged for your logic. Look at the Properties tab and change the "Server Side Method" property to "Yes".
Now that you have the method that returns an array, you could use it to automatically populate a dropdown field for an attribute in the BPM Object. You'd do this by opening the properties of the attribute and changing the "Valid Values" property to "Dynamic Method" and select the method you just added.
There's more to it than this, but hope this is enough to get you going,
Dan -
HELP: SQL*LOADER AND Ref Column
Hallo,
I have already posted and I really need help and don't come further with this
I have the following problem. I have 2 tables which I created the following way:
CREATE TYPE gemark_schluessel_t AS OBJECT(
gemark_id NUMBER(8),
gemark_schl NUMBER(4),
gemark_name VARCHAR2(45)
CREATE TABLE gemark_schluessel_tab OF gemark_schluessel_t(
constraint pk_gemark PRIMARY KEY(gemark_id)
CREATE TYPE flurstueck_t AS OBJECT(
flst_id NUMBER(8),
flst_nr_zaehler NUMBER(4),
flst_nr_nenner NUMBER(4),
zusatz VARCHAR2(2),
flur_nr NUMBER(2),
gemark_schluessel REF gemark_schluessel_t,
flaeche SDO_GEOMETRY
CREATE TABLE flurstuecke_tab OF flurstueck_t(
constraint pk_flst PRIMARY KEY(flst_id),
constraint uq_flst UNIQUE(flst_nr_zaehler,flst_nr_nenner,zusatz,flur_nr),
flst_nr_zaehler NOT NULL,
flur_nr NOT NULL,
gemark_schluessel REFERENCES gemark_schluessel_tab
Now I have data in the gemark_schluessel_tab which looks like this (a sample):
1 101 Borna
2 102 Draisdorf
Now I wanna load data in my flurstuecke_tab with SQL*Loader and there I have problems with my ref column gemark_schluessel.
One data record looks like this in my file (it is without geometry)
1|97|7||1|1|
If I wanna load my data record, it does not work. The reference (the system generated OID) should be taken from gemark_schluessel_tab.
LOAD DATA
INFILE *
TRUNCATE
CONTINUEIF NEXT(1:1) = '#'
INTO TABLE FLURSTUECKE_TAB
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS (
flst_id,
flst_nr_zaehler,
flst_nr_nenner,
zusatz,
flur_nr,
gemark_schluessel REF(CONSTANT 'GEMARK_SCHLUESSEL_TAB',GEMARK_ID),
gemark_id FILLER
BEGINDATA
1|97|7||1|1|
Is there a error I made?
Thanks in advance
Tigmultiple duplicate threads:
to call an oracle procedure and sql loader in an unix script
Re: Can some one help he sql loader issue. -
Hello everyone,
I’ve been assigned one requirement wherein I would like to read around 50 CSV files from a specified folder.
In step 1 I would like to create schema for this files, meaning take the CSV file one by one and create SQL table for it, if it does not exist at destination.
In step 2 I would like to append the data of these 50 CSV files into respective table.
In step 3 I would like to purge data older than a given date.
Please note, the data in these CSV files would be very bulky, I would like to know the best way to insert bulky data into SQL table.
Also, in some of the CSV files, there will be 4 rows at the top of the file which have the header details/header rows.
According to my knowledge I would be asked to implement this on SSIS 2008 but I’m not 100% sure for it.
So, please feel free to provide multiple approaches if we can achieve these requirements elegantly in newer versions like SSIS 2012.
Any help would be much appreciated.
Thanks,
Ankit
Thanks, <b>Ankit Shah</b> <hr> Inkey Solutions, India. <hr> Microsoft Certified Business Management Solutions Professionals <hr> http://ankit.inkeysolutions.comHello Harry and Aamir,
Thank you for the responses.
@Aamir, thank you for sharing the link, yes I'm going to use Script task to read header columns of CSV files, preparing one SSIS variable which will be having SQL script to create the required table with if exists condition inside script task itself.
I will be having "Execute SQL task" following the script task. And this will create the actual table for a CSV.
Both these components will be inside a for each loop container and execute all 50 CSV files one by one.
Some points to be clarified,
1. In the bunch of these 50 CSV files there will be some exception for which we first need to purge the tables and then insert the data. Meaning for 2 files out of 50, we need to first clean the tables and then perform data insert, while for the rest 48
files, they should be appended on daily basis.
Can you please advise what is the best way to achieve this requirement? Where should we configure such exceptional cases for the package?
2. For some of the CSV files we would be having more than one file with the same name. Like out of 50 the 2nd file is divided into 10 different CSV files. so in total we're having 60 files wherein the 10 out of 60 have repeated file names. How can we manage
this criteria within the same loop, do we need to do one more for each looping inside the parent one, what is the best way to achieve this requirement?
3. There will be another package, which will be used to purge data for the SQL tables. Meaning unlike the above package, this package will not run on daily basis. At some point we would like these 50 tables to be purged with older than criteria, say remove
data older than 1st Jan 2015. what is the best way to achieve this requirement?
Please know, I'm very new in SSIS world and would like to develop these packages for client using best package development practices.
Any help would be greatly appreciated.
Thanks, <b>Ankit Shah</b> <hr> Inkey Solutions, India. <hr> Microsoft Certified Business Management Solutions Professionals <hr> http://ankit.inkeysolutions.com
1. In the bunch of these 50 CSV files there will be some exception for which we first need to purge the tables and then insert the data. Meaning for 2 files out of 50, we need to first clean the tables and then perform
data insert, while for the rest 48 files, they should be appended on daily basis.
Can you please advise what is the best way to achieve this requirement? Where should we configure such exceptional cases for the package?
How can you identify these files? Is it based on file name or are there some info in the file which indicates
that it required a purge? If yes you can pick this information during file name or file data parsing step and set a boolean variable. Then in control flow have a conditional precedence constraint which will check the boolean variable and if set it will execute
a execte sql task to do the purge (you can use TRUNCATE TABLE or DELETE FROM TableName statements)
2. For some of the CSV files we would be having more than one file with the same name. Like out of 50 the 2nd file is divided into 10 different CSV files. so in total we're having 60 files wherein the 10 out of 60 have
repeated file names. How can we manage this criteria within the same loop, do we need to do one more for each looping inside the parent one, what is the best way to achieve this requirement?
The best way to achieve this is to append a sequential value to filename (may be timestamp) and then process
them in sequence. This can be done prior to main loop so that you can use same loop to process these duplicate filenames also. The best thing would be to use file creation date attribute value so that it gets processed in the right sequence. You can use a
script task to get this for each file as below
http://microsoft-ssis.blogspot.com/2011/03/get-file-properties-with-ssis.html
3. There will be another package, which will be used to purge data for the SQL tables. Meaning unlike the above package, this package will not run on daily basis. At some point we would like these 50 tables to be purged
with older than criteria, say remove data older than 1st Jan 2015. what is the best way to achieve this requirement?
You can use a SQL script for this. Just call a sql procedure
with a single parameter called @Date and then write logic like below
CREATE PROC PurgeTableData
@CutOffDate datetime
AS
DELETE FROM Table1 WHERE DateField < @CutOffDate;
DELETE FROM Table2 WHERE DateField < @CutOffDate;
DELETE FROM Table3 WHERE DateField < @CutOffDate;
GO
@CutOffDate which denote date from which older data have to be purged
You can then schedule this SP in a sql agent job to get executed based on your required frequency
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Need Help With SQL GROUP BY and DISTINCT
I am working on a project and need to display the total of each order based on the order id. For instance I want to display the order id, customer id, order date, and then the extension price (ol_quantity * inv_price).
I would then like a total displayed for order # 1 and then move on to order #2.
Here is my SQL code :
SELECT DISTINCT orders.o_id, customer.c_id, inv_price * ol_quantity
FROM orders, customer, inventory, order_line
GROUP BY orders.o_id, customer.c_id, inv_price, ol_quantity
ORDER BY orders.o_id;
When my code is run it displays the order id, customer id and inv_price * quantity (extension price) but no order total for the order number and a new group is not started when a new order number is started....they are all clumped together.
Any help is greatly appreciated!!Hi,
user12036843 wrote:
I am working on a project and need to display the total of each order based on the order id. For instance I want to display the order id, customer id, order date, and then the extension price (ol_quantity * inv_price).
I would then like a total displayed for order # 1 and then move on to order #2.
Here is my SQL code :
SELECT DISTINCT orders.o_id, customer.c_id, inv_price * ol_quantity
FROM orders, customer, inventory, order_line
GROUP BY orders.o_id, customer.c_id, inv_price, ol_quantity
ORDER BY orders.o_id;
When my code is run it displays the order id, customer id and inv_price * quantity (extension price) but no order total for the order number and a new group is not started when a new order number is started....they are all clumped together.
Any help is greatly appreciated!!Sorry, it's unclear what you want.
Whenever you post a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using.
Do you want the output to contain one row for each row in the table, plus an extra row for each distinct order, showing something about the order as a whole (e.g., total inv_price or average extension_price)? If so, you need GROUP BY ROLLUP or GROUP BY GROUPING SETS .
If you want one row of output for each row of the table, but you want to include something that reflects the group as a whole (again, e.g, total inv_prive or average extension_pcie), then you can us analytic functions. (Most of the aggregate functions, such as SUM and AVG have analytic counterparts that can get the same results without collapsing the result set down to one row per group.)
Here's an example of how to use GROUP BY GROUPING SETS.
Way we're interested in employees' salary and commission from the scott.emp table:
SELECT deptno
, ename
, sal
, comm
FROM scott.emp
ORDER BY deptno
, ename
;Output:
` DEPTNO ENAME SAL COMM
10 CLARK 2450
10 KING 5000
10 MILLER 1300
20 ADAMS 1100
20 FORD 3000
20 JONES 2975
20 SCOTT 3000
20 SMITH 800
30 ALLEN 1600 300
30 BLAKE 2850
30 JAMES 950
30 MARTIN 1250 1400
30 TURNER 1500 0
30 WARD 1250 500Now say we want to add the total income (sal + comm, or just sal if there is no comm) to each row, and also to add a row for each department showing the total sal, comm and income in that department, like this:
` DEPTNO ENAME SAL COMM INCOME
10 CLARK 2450 2450
10 KING 5000 5000
10 MILLER 1300 1300
10 8750 8750
20 ADAMS 1100 1100
20 FORD 3000 3000
20 JONES 2975 2975
20 SCOTT 3000 3000
20 SMITH 800 800
20 10875 10875
30 ALLEN 1600 300 1900
30 BLAKE 2850 2850
30 JAMES 950 950
30 MARTIN 1250 1400 2650
30 TURNER 1500 0 1500
30 WARD 1250 500 1750
30 9400 2200 11600(This relies on the fact that ename is unique.) Getting those results is pretty easy, using GROUPING SETS:
SELECT deptno
, ename
, SUM (sal) AS sal
, SUM (comm) AS comm
, SUM ( sal
+ NVL (comm, 0)
) AS income
FROM scott.emp
GROUP BY GROUPING SETS ( (deptno)
, (deptno, ename)
ORDER BY deptno
, ename
;Notice that we're displaying SUM (sal) on each row. Most of the rows in the output are "groups" consisting of only one row from the table, so the SUM (sa) for that goup will be the sal for the one row in the group.
Edited by: Frank Kulash on Nov 23, 2011 2:03 PM
Added GROUPING SET example
Maybe you are looking for
-
I opened an Excel file with multiple worksheets by doubleclicking on it, saved it as a Numbers file and made lots of changes to it. Now I can't open it at all. All I get is the message "The document (name) could not be opened." Any ideas?
-
Urgent problem: grouping by fields of internal table
Hi friend, i have a urgent problem and i hope that you can help me out: i have an internal table containing data, and i sorted it by 3 fields. now what i want to do is kind of grouping that means that all the lines that are the same should be written
-
Just need the link to download this plugin. All of the links I searched for redirect to https://creative.adobe.com/products. UPDATE: Here's the answer! You must download and install the "Creative Cloud" application with your existing Adobe ID. There
-
Dear all, We have oracle database 10.2.0.4 on solaris 5.10. We have 3 file systems /u01,/u02,/u03. u01 is hosting our oracle_home and u02,u03 holds database file systems. Currently SUN Admin has some corruptions in the file system u01 and he needs th
-
Regarding Ship to and Bill to Address on iStore.....urgent
Hi All, In Address of Ship to and Bill to , I need extra search based on Address1.. I am looking into jsp page;ibeCCkdSrchListAddr.JSP please give me any suggestions or steps to implement this feature. Thanks in advance.. Best Regards, HHH