Group by query, and then add another dimension
Hello guys,.
I am facing problem while building a query. In this, I do group first, and then add a column with a condition more.
I have following data in the table or existing query.
create table tableA (key number (5), newspaper varchar2 (5), varchar2 (5) Blog, available1 number (10), disponibles2 number (1), Type varchar2 (5))
Insert into tableA values (100, ' 501 ', ' 1501', 10000, 8000, "T1")
Insert into tableA values (100, ' 501 ', ' 1501', 12000, 0, 'T2')
Insert into tableA values (200, ' 502 ', ' 1505', 15000, 9000, "T11")
Insert into tableA values (200, '502', '1505', 8000, 1000, "T12")
Insert into tableA values (200, '502', '1505', 5000, 1000, "T13")
Insert into tableA values (300, ' 503 ', ' 1510', 7000, 6000, "T21")
Insert into tableA values (400, '503', '1510', 6000, 1000, 'T31')
I created the 'Difference' on the fly using NVL (available1, 0)-NVL(Revenue2,0) as the difference
Type of difference key1 journal Blog available1 disponibles2
100 501 1501 10000 8000 2000 T1
100 501 1501 12000 12000 T2
200 502 1505 15000 9000 6000 T11
200 502 1505 8000 1000 7000 T12
200 502 1505 5000 1000 4000 T13
300 503 1510 7000 6000 1000 T21
400 503 1510 6000 1000 5000 T31
Desired output
We must show Type (Sun) only when the difference is high and have to group by (Key1, Journal, Blog) while the rank becomes a.
It is like showing the first 6 columns first and then add the columns of 'Type' later (probably using subqueries).
Type of difference key1 journal Blog available1 disponibles2
100 501 1501 22000 8000 14000 T2
200 502 1505 28000 11000 17000 T12
300 503 1510 7000 6000 1000 T21
400 503 1510 6000 1000 5000 T31
Any idea or detail will be appreciated.
Thank you
Use the DUNGEON:
Select the key,
Journal,
blog,
Sum (revenue1) available1,
Sum (revenue2) disponibles2,
NVL (Sum (revenue1), 0)-nvl (sum (revenue2), 0) difference.
Max (type) keep (dense_rank last order of nvl(revenue1,0) - type nvl(revenue2,0))
from tablea
Key, group
Journal,
blog
order by key,
Journal,
blog
/
TYPE OF KEY JOURNAL BLOG AVAILABLE1 DISPONIBLES2 DIFFERENCE
---------- ----- ----- ---------- ---------- ---------- -----
100 501 1501 22000 8000 14000 T2
200 502 1505 28000 11000 17000 T12
300 503 1510 7000 6000 1000 T21
400 503 1510 6000 1000 5000 T31
SQL >
SY.
Tags: Database
Similar Questions
-
MAX value query and then add to existing querry
Hi all
Asked me to add some fields to add to an existing query.
I'm having a problem with the initial query, so let's start first, and then maybe I'll be able to figure out how to add it in.
Here is my sample data:
My desired output is the MAX (TASK_SEQ) based on the data set, the TASK_SEQ and the COMPL_DATE should always be recording albums that I'm trying to capture,CREATE TABLE TASK ( TASK_TYPE VARCHAR2 (50 BYTE), TASK_SEQ VARCHAR2 (50 BYTE), COMPL_DATE DATE, REQUIRED_TASK VARCHAR2 (100 BYTE) ); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('ABC',18, TO_DATE('12-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('DEF',16, TO_DATE('12-MAR-12','DD-MON-YYYY'),'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('HIJ',12, TO_DATE('09-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('KLM',15, TO_DATE('12-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('NOP',11, TO_DATE('11-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('QRS',20, TO_DATE('29-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('TUV',13, TO_DATE('11-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('WXY',19, TO_DATE('30-MAR-12','DD-MON-YYYY'), 'Y'); INSERT INTO TASK (TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK) VALUES ('Z',24, TO_DATE('04-APR-12','DD-MON-YYYY'), 'Y');
such as:
{Europe}
TASK_TYPE TASK_SEQ COMPL_DATE REQUIRED_TASK RNK
Z 24 4 4 2012 Y (DO NOT WANT THIS)I have this code that I thought would work, but not as of yet - it returns all rows and ranks eac as 1. {code} WITH DST AS ( SELECT TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK, RANK () OVER (PARTITION BY TASK_TYPE ORDER BY COMPL_DATE) rnk FROM TASK ) SELECT * FROM DST WHERE rnk = 1 {code} And this yields basically the same results: {code} SELECT TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK FROM TASK WHERE (TASK_TYPE, TASK_SEQ) IN (SELECT TASK_TYPE, MAX(TASK_SEQ) FROM TASK GROUP BY TASK_TYPE ) {code} Thanks for taking the time to look. G
Hello
GMoney says:
... Here is my sample data:Thank you! It is very useful.
... My desired output is the MAX (TASK_SEQ) based on the data set, the TASK_SEQ and the COMPL_DATE should always be recording albums that I'm trying to capture,
such as:
{Europe}
TASK_TYPE TASK_SEQ COMPL_DATE REQUIRED_TASK RNK
Z 24 4 4 2012 Y (DO NOT WANT THIS)
Be careful. The keyword tiny must code. (It must be spelled correctly, too.)
What is the desired line or line that you don't want? If this is the desired line, so you were on the right track with your first attempt. Try this:WITH DST AS ( SELECT TASK_TYPE, TASK_SEQ, COMPL_DATE, REQUIRED_TASK, RANK () OVER (ORDER BY COMPL_DATE DESC) rnk FROM TASK ) SELECT * FROM DST WHERE rnk = 1 ;
Exactly what you have published, with the exception of the analytical clause.
'PARTITION BY task_type' means a separate set of numbers (starting with 1) assign to each separate task_type. Since task_type is unique, this means that each line is #1 in his own little world. If I understand the problem, you want (except ties) only 1 rank for the entire result set. This means you don't at all want a PARTITION BY clause. PARTITION BY is never required in any analytic function.
"ORDER BY compl_date" means that the first compl_date gets rnk = 1. You want the latest comp_date to get #1, so you must specify descending order. Note that this has nothing to do with task_seq. It you want to display the line with the highest task_seq, then the rnk column would be defined as:RANK () OVER (ORDER BY task_seq DESC) rnk
If you know that the line with the upper task_seqs is always compl_dates later, then it does not matter that you use. Remember to descending order.
-
Button makes visible subform, and then adds another instance
Hello
I have a button that makes a subform visible. Which works very well.
I would like the button when a user clicks a second time to add another instance of the same subform. Is this possible? I have no idea how start with the JavaScript for this and would appreciate help.
Thanks in advance,
MDawn
Rather than raise the subform, and then adding cases you can do simply by using the instances, then the button does the same thing.
To 'hide' the subform using the instances, make sure that under binding that the Min County click on and the initial count is set to 0 (zero) - your subform is now hidden by default.
Change the code you have showing the subform to use addInstance() instead of the presence, using the underscore for the Instance Manager shortcut (you must use the underscore method, because the instance does not yet exist):
_hiddenSubform.addInstance (true);
If you remove instances to zero then the subform will disappear again. Doing it this way also has the advantage of reset all data in the subform.
-
Try to add a page to a pages document. It worked until now but just finished page 13 with text and photos and cannot add another page, using macbook pro with El Capitan and the most recent version of the Pages.
You have placed your beam to insert at the end of your text on page 13 and then apply Insert menu: Page Break? In the v5.6.2, Pages I just add a new page to a section of four pages to this approach.
-
Effectively remove and then add the piece of table 2D
I have a table that is 72 lines (32 channels, 8 channels, 32 channels). I am now taking the middle 8 channels and move it to the end, he will be 32, 32, 8. I could delete a subset of the table, and then add at the end, but I think that it would cause 2 allowances. I wonder if there's a cleaner way to achieve inplace?
Take 2 table subsets (32.8) (40,24) can do two replacements in the original array (index of 64 and 32). I find that it is usually two times faster than delete + rebuild (to research cleaner), which is two times faster than the IPES (slower and uglier by far). Your mileage may vary. It's all the microseconds at this size of table.
-
In Adobe buy screen serial number, the "Download" button directed me to a download Avarto Bertelsmann. I have too drive my Mac, security s and downloaded files. Avarto installation was a failure and then found another site of Adobe which was a success. Should I be concerned about the unsuccessful Avarto download?
I've never heard of this person/company/link... but I'm not on Windows, Mac
-
Hello Hello. If I have Adobe audition, can I install first program in my laptop, and then in another (if I decide to change my cell phone for a newer laptop)?
You can install hearings on as much as you can, there are not limited to the facilities. However if you had bought the individual subscription, you can log in and activate the app as a full version on 2 devices only.
If you buy a new device and want to activate on the same, all you have to do is simply disconnected from Adobe Creative Cloud application of either of the 2 previous devices, so that you can maintain the number of activations that 2.
You can switch activation between devices, no problem.
Let us know if you need more details.
-
I have Visual Studio 2010 Professional. On the start page, I started with file, new Web Site and you click New ASP.NET Web Site. I created a new web site and added a default.aspx page. I want to create a library of classes (entity component) and then use the Solution Explorer window to add a reference to the class library project to the web site solution. I'm trying to do from the start. in other words, a request has not created to which I simply add web pages. Is this possible?
Or do I make file, new project, and create a new web application in place initially to create the class library and to add a reference in the Visual Studio solution.
Hello
Check out these resources:
MSDN - Visual Studio Developer Center
http://msdn.Microsoft.com/en-us/vstudio/defaultVisual Studio MSDN forums
http://social.msdn.Microsoft.com/forums/en-us/category/VisualStudioMSDN Visual Studio, and related Forums
http://social.msdn.Microsoft.com/forums/en-us/category/vsvnext, visualstudio, vsarch, vsdbg, vstest, vstfs, vsdata, vsappdev, visualbasic, visualcsharp, end, visualfsharpI hope this helps.
Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="">-><- mark="" twain="" said="" it="">->
-
I'm trying to understand vSphere PowerCLI how to activate the "Options of VAPP" on an exsiting VM (in this case a model freshly cloned) then add properties and select cdrom of the FVO data access such as when the virtual machine is running the FVO - env.xml contains the properties in the CD-ROM drive.
If I use the vSphere client and open the virtual machine settings and click on the tab 'Options' and then select "Options of VAPP" and change the setting to "Enabled" and then select 'VAPP-> Advanced Options' and click on the button 'Properties' on the right, I can add the properties and then I can change them vsphere PowerCLI, but given that these actions are not retained if I clone the virtual machine I need a way to put these in place of vSphere PowerCLI without using the vSphere client to do.
Thanks in advance for the help!Mike
You can use the vSphere API to activate the 'Options of VAPP"on an existing virtual machine, and set properties. For example:
$spec = new-Object VMware.Vim.VirtualMachineConfigSpec
$spec.vAppConfig = new-Object VMware.Vim.VmConfigSpec
$spec.vAppConfig.property = new-Object VMware.Vim.VAppPropertySpec [] (1)
$spec.vAppConfig.property [0] = new-Object VMware.Vim.VAppPropertySpec
$spec.vAppConfig.property [0] .operation = 'Add '.
$spec.vAppConfig.property [0] = new-Object VMware.Vim.VAppPropertyInfo .info
$spec.vAppConfig.property [0].info.key = 0
$spec.vAppConfig.property [0].info.classId = "Property1ClassID".
$spec.vAppConfig.property [0].info.instanceId = "Property1InstanceID".
$spec.vAppConfig.property [0].info.id = "Property_1.
$spec.vAppConfig.property [0].info.category = "Property1Category".
$spec.vAppConfig.property [0].info.label = "property 1.
$spec.vAppConfig.property [0].info.type = "string".
$spec.vAppConfig.property [0].info.userConfigurable = $true
$spec.vAppConfig.property [0].info.defaultValue = "Property1DefaultValue".
$spec.vAppConfig.property [0].info.value = «»
$spec.vAppConfig.property [0].info.description = "Property1Description".
$vm = get-VM-name vm3
$vm. ExtensionData.ReconfigVM_Task ($spec)
-
How do I search a Movieclip given stage and then add all instances of it in a table? AS3
I would like to add multiple instances of a Movieclip, (name of the library = bats | instance name = none), inside an another Movieclip (name of the instance = back.visuals) / / (by HAND) NOT addChild (mc_name); Easy
If someone could help me with the code to perform the following steps:
Search the Movieclip, (name of the instance = back.visuals), which contains the Movieclips, (= bats library name: instance name = none), added manually to the scene at hand.
Then, for all instances of this movieclip (= bats library name: instance name = none) add them to a table.
Thank you
Dyami
Assuming that you are talking about DURATION, if you export a symbol of action script, give it a class name you can always read if the child of an object is an instance of that symbol.
Say, if the name of the symbol is bats you can identify it in the loop as follows:
var enemyList:Array = []; for (var i:int = 0; i < back.visuals.numChildren; i++) { var child:DisplayObject = back.visuals.getChildAt(i); if (child is Bats) { enemyList.push(child); } }
-
How a tab groups exist after a close and restart FF? or why the content of a group of tabs disappear if the tab is closed?
See how to use tab groups to organize a large number of tabs
-
I am an intern for a company and they asked me to pass their already plugged into the adapter of desk Goflex usb 3.0 backwards Server Office Goflex USB 3.0 adapter. They mentioned that I unplug before the one that is already attached to the Windows 2008 R2 Standard Server, I want to stop the automatic updates and cut it (I don't know if they mean turn off Office Goflex usb 3.0, a server adapter or updates).
Then plug back up Server Office Goflex usb 3.0 adapter. When it is plugged in that they said to go back to the top.
My main question is how to do it safely with ruin them anything? My second question is what are the steps to remove the device already plugged into the computer? My third question is, what are the steps to configure the server to the top device once I plug?
They have done this before, I can tell because there are 2 dates on a note of sticky notes on the backup server. I know that the Goflex desktop adapter is not really a matter of Microsoft but I tried to contact Seagate and they told me to contact Microsoft.
Thank you!
Hello
Post your question in the TechNet Server Forums, as your question kindly is beyond the scope of these Forums.
http://social.technet.Microsoft.com/forums/WindowsServer/en-us/home?category=WindowsServer
See you soon.
-
Newbie, trying to close and then choose another file
Hello
I'm doing a very simple script just to close a file and open a specific folder so I can choose another. Finally, I would like to learn much more, but even if that will allow me to save some work.
Closes the file that follows and shows the right folder but when I click on the file I want to open the name appears in the "File name" box, but it does not open, and I get an error message. If I specify the name of the file with the path, it opens but I want to be able to choose the file.
app.activeDocument.close (SaveOptions.no);
File.openDialog ("path");
I searched a lot a response but perhaps not using the right conditions?
Thank you
Gary
With File.openDialog (), you open the last used folder. To open a folder specified, use openDlg() instead. For example:
f = Folder ('/d/test').openDlg ("Select a file"); if (f !== null) { app.open(f); }
See the 'JavaScript ToolsGuide CC' (helping the ESTK) file for details. It is useful filter the list of files. For example, to display only the indd files, use this:
f = file ('/d/test').openDlg ('Select files', ' InDesign: * .indd ');)
Peter
-
installed programs do not come up. I can't remove the software free stupid who talk about problems but cannot fix them unless I have buy it upgrade.
Apparently, your computer is infected with a rogue security program that has damaged the system. It's called "thugs" because he pretended to be a good guy but is really bad. Don't pay them! You will need to clean the machine first.
Search for removal here Bleeping Computer how removal steps - of - http://www.bleepingcomputer.com/forums/forum55.html
or here - Malwarebytes malware removal Guide - http://tinyurl.com/5xrpftMalwarebytes' Anti-malware (MBAM) or SuperAntiSpyware will often do the job. Both have free versions and you don't need to buy these programs.
These can work for you, and all can be good. However, in many cases the computer will also infected with other horses of Trojan and protected by a rootkit. These machines are extremely difficult to clean. If your machine is one of these cases, either the interactive assistance to one of the specialty forums listed in the link below, OR take your machine to a professional on the local computer OR backup your data and do a clean install of Windows. It's your choice. I do not recommend using BigComputerStore/GeekSquad types of places.
http://www.elephantboycomputers.com/page2.html#HJT-links
MS - MVP - Elephant Boy computers - don't panic! -
Custom post and then update another field in Acrobat 5
I am using Acrobat 5 (all, I have access to) to make a form.
I have a column of values and a column of judgments. If the value is not within the tolerance, the judgment must be defined to FAIL, otherwise, it is set to PASS.
There are four pages, and the fields are named IV [Page] [field] and J [Page] [field] (IV201, J313).
The problem I have is to get the script to work.
[code]
var f = this.getField ("IV201");
var g = this.getField ("J201");
If (f.value < 79.205 | > 80.805 f.value)
{
g.Value = "FAIL";
}
on the other
{
g.Value = "PASS";
}
The only time where changes in field stop at the COLLAR is when the value is greater to and NOT equal to 80.805. In games of tolerances to FAIL. Below, the low tolerance sets to FAILURE. I tried different combinations of if... else if else and nothing works.
Thank you
Phoneix
P.s. If anyone knows a quick way to apply this control to 100 fields I appreciate help there too.
Message has been changed because PhoenixofMT forgot to close its section of code.
Never mind. I guess you cannot actually change the body of the message.
Try this:
Get the value of this field as a number
var val = + event.value;
var g = getField ("J201");
If (val < 79.205="" ||="" val=""> 80.805)
{
g.Value = "FAIL";
}
on the other
{
g.Value = "PASS";
}
Maybe you are looking for
-
How can I remove a UN server used in the drop-down list?
Cannot remove an old server in my menu drop-down. May add one, but not delete.
-
I had two incidents recently where FireFox will simply display a blank screen. In both cases when I tried the same website in Google Chrome, Chrome displays an error message which helped me to solve the problem. Firefox just sits there without unders
-
How can I enable LAN card in my Satellite A100-413?
Hello I just installed Win XP operating system and also all the drivers (graphics driver driver audio, etc.). All of them work fine, except the network card. I can't? t find the network card on my XP system. I can't find 1394 Net Adapter but when I l
-
How to merge 2 files of Outlook Express dbx
How can I combine 2 DBX files with the same name (Outlook Express 6 on Windows XP) into one? PS a Automatic compaction of my sent items box is not a month. So, all of my sent emails disappear from Outlook Express. Save sent messages before the crash
-
My refuses to mouse click until I opened the task manager - what could be the cause?
I installed Windows 7 pro on my laptop (64 bit) and for some reason, when I start the computer, on which the mouse will be able to move, but can't select anything or click. When I fly over things that should light up, nothing seems to happen. I have