SQL Help with Time Period vs Time Period Comparison
Hello,
I am trying to create a query that will provide me a result set that will have current revenue (based off user selection of time) compared to another set of revenue with a different time period.
For example:
select a.xx_adm_adv_id, a.xx_edition, sum(a.xx_net_space)
from ps_xx_adm_work_ord a
where A.xx_issue = 'JAN'
AND A.XX_ISSUE_YEAR = '2011'
group by a.xx_adm_adv_id, a.xx_edition
will provide my current data set, now I want to pull in the result set below, but in the 4th column based off of XX_ADM_ADV_ID & XX_EDITION (no repeats for these combinations).
select B.xx_adm_adv_id, B.xx_edition, sum(B.xx_net_space)
from ps_xx_adm_work_ord B
where B.xx_issue in ('JUN', 'JUL')
AND B.XX_ISSUE_YEAR = '2012'
group by B.xx_adm_adv_id, B.xx_edition
So essentially, I should be seeing all xx_adm_adv_id and xx_edition for both time periods and data in atleast one set of columns (3rd or 4th)
I am running 10.2.0.4.0
Many thanks in advance!
Did you try the query that i provided?
Commented XX_ISSUE_YEAR condition,adjust it to meet your requirements.
SQL>
SQL> select distinct a.xx_adm_adv_id,
2 a.xx_edition,
3 sum(case
4 when xx_issue = 'JAN'-- and XX_ISSUE_YEAR = '2011'
5 then
6 a.xx_net_space
7 else
8 0
9 end) over(partition by a.xx_adm_adv_id, a.xx_edition),
10 sum(case
11 when xx_issue in ('JUN', 'JUL')-- and XX_ISSUE_YEAR = '2012'
12 then
13 a.xx_net_space
14 else
15 0
16 end) over(partition by a.xx_adm_adv_id, a.xx_edition)
17 from PS_ORDER a
18 where A.XX_ISSUE in ('JAN', 'JUN', 'JUL')
19 --AND A.XX_ISSUE_YEAR in ('2011', '2012')
20 order by a.xx_edition
21 ;
XX_ADM_ADV_ID XX_EDITION SUM(CASEWHENXX_ISSUE='JAN'--AN SUM(CASEWHENXX_ISSUEIN('JUN','
000016004 NAT 5722.2 2861.1
000016073 REG 5111.12 0
000025008 REG 0 2665.32
SQL>
Similar Messages
-
Help with iTunes database and Time Machine after Lion clean install
I did a clean install of OS X Lion and think I've given myself problems with my Snow Leopard Time Machine backup and with my iTunes Library database files.
My iMac (2007) had become very sluggish so I opted for a clean install. Before the install of Lion my Snow Leopard 10.6.8 internal 1TB HD was at about 600GBs. I was using Time Machine to backup to an external 1TB drive. I had my iTunes 10.? library on the same drive.
For the Lion install I partitioned my internal 1TB HD into two partitions - a 250GB Lion boot partition and the rest for Lion data files.
Now I have two problems - 1. I can't work out how to re-connect my Time Machine backups, since they were related to a much bigger original drive, and 2. I can't seem to find my iTunes database files.
I also don't want to restore any application files at this stage, as I'm determined to do a fresh install of only the applications I need as I go along, and hopefully avoid the issues of sluggishness I had with Snow Leopard.
I have all my iTunes files in their pre-Lion external HD folder, but that folder does not seem to have the iTunes Library.XML or iTunes Library files. I didn't delete them so I'm hoping they were in my iTunes folder on my SL boot drive. But that drive was deleted during the install, so I'll be depending on Time Machine to restore the database.
Can anyone suggest a way to deal with Time Machine for my Lion install, and a way to restore my iTunes database? I'd like to keep as much of the Snow Leopard Time Machine data as I can, while continuing to do Time Machine backups from my Lion installation.
Anyone know where iTunes stores those database files, if not in the external drive iTunes folder? Spotlight search doesn't find the files, but is there a way to search my old Time Machine backups without having the Time Machine backups folder re-connected in Lion?
Thanks.My iTunes folder is organised like this if it helps:
And iTunes uses them from the Prefrences like this:
Regards,
Colin R. -
I need help with the .xinitrc (first time arch user)
I just installed Arch on a virtual machine and i am following the beginner guide step by step.
I have reached the point that i enable gnome-session to start automatically when you invoke startx.
The guide says i need to add the line "exec ck-launch-session gnome-session" in the xinitrc file.
I tried doing this in the root account and the system just doesnt login to gnome. I tried doing it using the normal user and the files just disappears, and cannot be edited.
I looked around on the internet and found that typing startx /usr/bin/gnome-session startx gnome, but it doesnot replace startx or starts automatically.
this is my first time using arch and i would like help.
Thank you.You probably think the file "disappears" because .xinitrc is a "dot" file, which normally doesn't show up in an ls listing. Any file whose name begins with a '.' is a "hidden" file and generally doesn't show up in any listing. 'ls -a' to see it.
And please note that it is the file .xinitrc - ie, it begins with a period. This is the file that is looked for by X at start up. -
Can someone help with Iphoto 09 and Time Machine
I upgraded to ilife 09.....I am having problems between iphoto and time machine. All my photos are in iphoto but when I went to see if everything was ok in time machine all I find are blank windows no photos from iphotos are in there.
Everything was OK in iLife 08.....and now this problem.
Please help.
TerryTerry
I don’t understand:
Browse backups...it worked...I did see all the photos in time machine.
doesn;t seem to tally with
After trying yours suggestion I than clicked on iphoto and opened time machine and it was empty.
The way to access photos in TM is via the Browse Backups command.
Regards
TD -
Help with setting up microcell-time capsule-dsl
how do i set up time capsule with motorola nvg510 router and microcell by at&t
The express is also connected via ethernet to the Time Capsule so I can use it for my iPhones and such that do not have N. If I am on the Macbook and I am on the Time Capsule network, is there a way to not have to switch wireless networks to the Airport Express just to listen to Air Tunes?
Yes. Just reconfigure the AirPort Express Base Station (AX) as a bridge.
(ref: AirPort Utility > select the AX > Manual Setup > Internet > Internet Connection > Connection Sharing = Off (Bridge Mode)) -
Help with Query - Duration Calculation/Time Overlap
Hello All,
Here is the scenario.
We have a table of events which has event id, start datetime and end datetime. This is essentially a calendar of a person.
EventID StartTS EndTS
21 8 AM 4 PM
20 9 AM 11 AM
18 3 PM 4 PM
2 10 AM 12 AM
The result I need is event id, duration where the duration is the duration of the event minus the overlap duration of any other event with event id less than the current event id.
Answer :
EventID StartTS EndTS Duration Overlap
21 8 AM 4 PM 8 - 4 = 4 All below 3 event
20 9 AM 11 AM 2 - 1 = 1 EventID #2
18 3 PM 5 PM 2 No Overlap
2 10 AM 12 PM 2 No Overlap
Thanks for you help!scott@ORA92> CREATE TABLE events
2 (EventID NUMBER,
3 StartTS DATE,
4 EndTS DATE)
5 /
Table created.
scott@ORA92> INSERT INTO events VALUES (21, TO_DATE ( '8 AM', 'HHAM'), TO_DATE ( '4 PM', 'HHPM'));
1 row created.
scott@ORA92> INSERT INTO events VALUES (20, TO_DATE ( '9 AM', 'HHAM'), TO_DATE ('11 AM', 'HHPM'));
1 row created.
scott@ORA92> INSERT INTO events VALUES (18, TO_DATE ( '3 PM', 'HHAM'), TO_DATE (' 5 PM', 'HHPM'));
1 row created.
scott@ORA92> INSERT INTO events VALUES ( 2, TO_DATE ('10 AM', 'HHAM'), TO_DATE ('12 PM', 'HHPM'));
1 row created.
scott@ORA92> COMMIT
2 /
Commit complete.
scott@ORA92> ALTER SESSION SET NLS_DATE_FORMAT = 'fmHH AM'
2 /
Session altered.
scott@ORA92> SELECT * FROM events
2 /
EVENTID START ENDTS
21 8 AM 4 PM
20 9 AM 11 AM
18 3 PM 5 PM
2 10 AM 12 PM
scott@ORA92> SET SERVEROUTPUT ON FORMAT WRAPPED
scott@ORA92> DECLARE
2 v_overlap NUMBER;
3 v_ts DATE;
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE ('EventID StartTS EndTS Duration Overlap Duration-Overlap');
6 FOR rec1 IN
7 (SELECT eventid, startts, endts,
8 (endts - startts) * 24 AS duration
9 FROM events)
10 LOOP
11 v_overlap := 0;
12 v_ts := rec1.startts;
13 FOR rec2 IN
14 (SELECT *
15 FROM events
16 WHERE eventid < rec1.eventid
17 AND startts < rec1.endts
18 AND endts > rec1.startts
19 ORDER BY startts)
20 LOOP
21 v_ts := GREATEST (v_ts, rec2.startts);
22 IF rec2.endts > v_ts
23 THEN
24 v_overlap := v_overlap + ((LEAST (rec2.endts, rec1.endts) - v_ts) * 24);
25 v_ts := LEAST (rec2.endts, rec1.endts);
26 END IF;
27 END LOOP;
28 DBMS_OUTPUT.PUT_LINE
29 (LPAD (rec1.eventid, 7)
30 || ' '
31 || LPAD (rec1.startts, 7)
32 || ' '
33 || LPAD (rec1.endts, 7)
34 || ' '
35 || LPAD (rec1.duration, 8)
36 || ' '
37 || LPAD (v_overlap, 7)
38 || ' '
39 || LPAD ((rec1.duration - v_overlap), 16));
40 END LOOP;
41 END;
42 /
EventID StartTS EndTS Duration Overlap Duration-Overlap
21 8 AM 4 PM 8 4 4
20 9 AM 11 AM 2 1 1
18 3 PM 5 PM 2 0 2
2 10 AM 12 PM 2 0 2
PL/SQL procedure successfully completed. -
Please help with usage and standby time...
I see these posts about usage and standby time. In one case the stand by on his phone is three (3) days.
I just did a complete charge, a hard reset and right now my standby is only at 2 hours 28 minutes, and the battery meter is showing 97% battery life left. Apple says the stand by time can be as much as 300 hours, or 12 days
I have spoken to the help desk and they are not much help at all.
Why is my stand by so low….
Need help pleasePossible scenarios for low battery life:
1. You're fetching new data for accounts every 15 minutes (Settings/Mail/Fetch New Data).
2. You have background apps running (Skype, AIM, other social network or communication apps).
3. Your GPS is active (navigation apps).
4. FaceTime is on (Settings/Phone). -
Help with export speed - First time poster - please be gentle!!
Hi all,
Currently an i5 win 7 with 4gig ram (work PC!!!)
Using Ppro 8.1.0 (81)
As a company we have upgraded from CS6 to CC in the last month
I have played around an everything is looks fine, but I have a 40 second video containing 4 After Effect comps fully rendered sitting on my Ppro timeline. I go to export and choose h2.264 720p 25 as I would have done in CS6 and the estimated file size is 48meg, So I'm thinking that will be a quick render.
At the moment the estimated time reads 2 hours and 7 mins and is climbing!!
What am I doing wrong? I usually export to this setting and a 4 min video on the same machine using CS6 used to take about 45 mins
Thanks in advance, I have looked through the forums, but don't know much about the ins and outs of hardware acceleration or even know where to find it!!
AndyHi all,
Currently an i5 win 7 with 4gig ram (work PC!!!)
Using Ppro 8.1.0 (81)
As a company we have upgraded from CS6 to CC in the last month
I have played around an everything is looks fine, but I have a 40 second video containing 4 After Effect comps fully rendered sitting on my Ppro timeline. I go to export and choose h2.264 720p 25 as I would have done in CS6 and the estimated file size is 48meg, So I'm thinking that will be a quick render.
At the moment the estimated time reads 2 hours and 7 mins and is climbing!!
What am I doing wrong? I usually export to this setting and a 4 min video on the same machine using CS6 used to take about 45 mins
Thanks in advance, I have looked through the forums, but don't know much about the ins and outs of hardware acceleration or even know where to find it!!
Andy -
Help with a query regarding time dependent display of Plan/Actual data
Hello,
Let me try to explain what my problem is:
I have a query that shows plan and actual sales figures on a timeline. Plan and actual data is identified by 0VERSION (P01 for Plan; P00 for Actual).
0CALMONTH and Sales key figure is in rows. 0VERSION is in collums.
The output looks as follows (simplified):
CalYYYY/MM............P01....P00
2006.09......Sales........90.....100
2006.10......Sales......100.......95
2006.11......Sales........90........0
2006.12......Sales........95........0
So far so good! But users aren't satisfied with that. They want only <u>one</u> collumn with sales figures. For past months (< 2006.11) they want to see actual figures (Version P00). For current and future month (>= 2006.11) they want to see plan figures (Version P01). And this only in one single collumn.
So the output should look this way:
CalYYYY/MM..........P00/P01
2006.09......Sales......100
2006.10......Sales.... ...95
2006.11......Sales........90
2006.12......Sales........95
Is there any way/workaround to accomplish this?
Your help will be very appreciated!
Regards,
UlrichHi,
For this what you can try is , have the two Restricted Key Figs the way you have right now, but Hide them. Then Create a Third Formula Key Fig, in which you can put a Boolean Logic :
(FV > 11) * Act KF +(FV<= 11)*Plan KF
Where FV is a Formula Variable which takes on the Value from Month (1 for Jan , 2 for Feb etc)
Try something on these lines. -
MSI Neo4 Plat SLI. Help with sli setup (rma time)
Hi everyone.
I'm new to the sli world. I am having an issue with setting up the second video card. Runs great with one card as soon as I install the second card and try to play a game or run 3dmark03 the screen goes blank and the system reboots. I reversed the sli card made sure it was seated good, enabled the nvidia settings to dual cards.
Is there a bios setting? I might be missing or something. Please help this newbe, I'm getting frustrated.
Thanks.Anyone?????? I am going to RMA this sucker.....Updated to 3.30 and now it doesnt see the other video card. try to shut down and it reboots....aaaahhhhhhgggg .......Can not get a hold of MSI tech support (Non existant).....Hmmmm should tell me something.
Sorry for venting -
Help with itunes and quick time
IT wont let me open my itunes now i get a pop up saying that my quicktime is to old 7.1 or something which i thought was upto date and it says it requires 7.1-7.3 and to reinstall itunes. So i guess my question is, do i have to unistall my itunes ( will i loose all my songs) or is there an easier way.
THANKSlet's try swapping out your QuickTime instead.
head into your Add/Remove programs. uninstall QuickTime.
Next, we’ll manually remove any leftover program files and folders.
1. On the Start menu, click My Computer (or double-click My Computer on the Desktop).
2. In My Computer, open Local Disk.
3. Open Program Files.
4. Right-click on the QuickTime folder and click Delete from the shortcut menu.
5. Navigate to C:\Windows\system32\.
6. Remove the files QuickTime.qts and QuicktimeVR.qtx.
7. Restart your computer.
next, we'll get a fresh copy of QuickTime into your PC by doing a repair install of itunes.
switch off antivirus and antispyware applications prior to the repair install.
go into Add/Remove and select itunes. click "Change" and then click "Repair".
if the repair install goes through okay, restart the PC and try launching itunes again. does it launch properly now? -
Help with syncing for first time..
I am wondering how to sync my email and iphone so that they are both updated simultaneously? Thanks
Check the servers used in your account settings on your computer. If your incoming mail server is pop.whatever.com, for example, it's a POP account. Some (e.g. gmail) can be set up either way.
-
Oracle SQL HELP with convert GMT to EST and DST and Date offset
Hi, I have a query that does not seem to work trying to convert a date field that is in GMT to est and using extract(timezone_hour FROM TO_TIMESTAMP_TZ as an offsetr
HEre is my sql
dtl.start_dt_gmt + (extract(timezone_hour FROM TO_TIMESTAMP_TZ( dtl.start_dt_gmt,'DD-MON-YYYY HH24:MI:SS TZH:TZM'))/24 ) START_DT_Local
If the date (dtl.start_dt_gmt) is may 1 and gmt starts at 04:00 AM , the extract offset produces -4
However, if the date (dtl.start_dt_gmt) is Feb 1 which begins at 05:00 AM GMT, the date offset still gives 04. What am i doing wrong? Any help would be appreciated. Thanks.
SaulIf your data is not associated with timezone then you'll have to use something like
case when dt between A and B then dt-1/24 else dt end; <-- This will give you 1 hour back of EDT. So, as far as concern at database level, it is nothing to do at db level, because db is used by application, so you need to code in the app.
Oracle never actually changes a TIMEZONE column value when you set your system to be on daylight savings time. There are several built-in DST DATE conversion functions for changing to daylight savings time:
current_date
current_timestamp
localtimestamp
dbtimezone
sessiontimezone
extract
from_tz
to_timestamp
to_timestamp_tz
to_yminterval tz_offset
http://dba-oracle.com/t_oracle_daylight_saving_time_dst_date_conversion.htm
Regards
Girish Sharma -
N00b is in ddesperate need of some SQL help with parameters
SO I am trying to create a report that will allow the operator to select an application name (appname from table) which I have working as a ripoff of the AdventureWorks db for passing parameters (stored procedure);
USE [Test]
GO
/****** Object: StoredProcedure [dbo].[App_Get] Script Date: 2/19/2015 9:40:58 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[App_Get]
@GetName NVARCHAR(500)
AS
BEGIN
;WITH CTE1
AS
SELECT CAST(('<i><j>' + REPLACE(@GetName, ',', '</j></i><i><j>') + '</j></i>' ) AS XML) CSV
),CTE2
AS
SELECT CAST(i.query('./text()') AS VARCHAR(100))CSV
FROM CTE1
CROSS APPLY CSV.nodes('/i/j') As x(i)
SELECT * FROM ae_apps
WHERE appname IN (SELECT * FROM CTE2)
END
AND I have the script that will allow me to pull the information from the multiple tables;
select ae_login.usrid, ae_login.usrnam, ae_login.fullnam, ae_audit.tsstamp, ae_audit.eventid, ae_agdesc.description, ae_audit.appid, ae_apps.appname
FROM ae_login, ae_audit, ae_agdesc, ae_apps
WHERE ae_login.usrid = ae_audit.usrid
AND ae_audit.eventid = ae_agdesc.eventid
AND ae_audit.appid = ae_apps.appid
order by ae_audit.appid, ae_audit.tsstamp
BUT I do not know how to tie that selected parameter (appname) from the dropdown list. Essentially I want the operator to select the (appname) and have the report generate the audit information from script above for just that selected (appname).
Any Thoughts would be appreciated.Hi cnelsonaa27,
According to your description, you want to add parameter to the report, then users can select an application name from the parameter drop down list when they preview the report, but you don’t know how to tie the dataset and parameter, right?
To achieve the goal, please refer to the following steps:
1. In design surface, in Report Data pane, right-click Data Sources and click Add Data Source.
2. Type data source name, select Embedded connection, then type select Type and type connection string, or select a shared data source.
3.Right-click Datasets and click Add Dataset.
4.Select Use a dataset embedded in my report, the default name is Dataset1, then select data source you added in step2, then copy the query to Query text box:
select ae_login.usrid, ae_login.usrnam, ae_login.fullnam, ae_audit.tsstamp, ae_audit.eventid, ae_agdesc.description, ae_audit.appid, ae_apps.appname
FROM ae_login, ae_audit, ae_agdesc, ae_apps
WHERE ae_login.usrid = ae_audit.usrid
AND ae_audit.eventid = ae_agdesc.eventid
AND ae_audit.appid = ae_apps.appid
order by ae_audit.appid, ae_audit.tsstamp
5.Right-click Datasets and click Add Dataset.
6.The default name is Dataset2, select data source from drop down list, then copy the query used to create parameter to Query text box.
7.Right-click Parameters and click Add parameter, type parameter name and prompt.
8.Click Available Values in left pane, select Get values from a query, select Dataset2 from Dataset drop down list, select appname as Value field, select appname as Label field.
9.Right-click Dataset1 to open Dataset Properties dialog box, click Filters in left pane, click Add button.
10.Select appname from Expression drop down list, set Operator to =, then set value to [@ParameterName], click OK.
For more information about Adding Parameters to a Report, please refer to the following document:
https://technet.microsoft.com/en-us/library/aa337432%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
Wendy Fu
TechNet Community Support -
SQL help with calculation uptime from event logs
Hi guys,
I'm able to retrieve uptime/downtime info from the eventlogs using the 6005, 6006 events. I just realized that there are cases (dirty shutdowns) where there may not be a shutdown (6006) logged. There will be a 6008 message logged though. I am kinda stumped as to how to match up the 6006 and 6005 messages now to calculate uptime as there might be a few more 6005 messages than 6006. Any ideas. Here's what I have so far: I'm querying the MOM reporting database.
select t1.computername ServerName,
t1.computerdomain ComputerDomain,
t1.timegenerated ShutdownTime,
(select min(t2.TimeGenerated) from SDKEventView t2
where t1.ComputerName = t2.computername
and NTEventID = 6005
and t2.timegenerated >= t1.TimeGenerated) StartupTime,
datediff(minute,t1.TimeGenerated, (select min(t2.TimeGenerated) from SDKEventView t2
where t1.ComputerName = t2.computername
and NTEventID = 6005
and t2.timegenerated >= t1.TimeGenerated)) Downtime
from SDKEventView t1
where t1.NTEventID = 6006
and t1.timeGenerated between '5/1/2005 12:00:00.000 AM' and '5/2/2006 12:00:00.000 AM'
and t1.computername in (select name from sdkcomputerview where name like '%FLK%')
order by DowntimeWhat I would do is create a class with the stored procedure call as one of the methods:
Class Accessor()
public UsrObject getUser(String loginId)
//put stored procedure here>
//after getting data from database, put into an
// object you define (ie: UsrObject)
return UsrObject
}You have a couple of other issues you need to address (and they may already be taken care of)
You need to decided if this is a 2-tier or 3-tier architecture. Are you accessing the database directly without going through a middle tier?
Maybe you are looking for
-
My new macBook Pro Retina won't connect to my wifi. Password IS CORRECT.
I just got a new-in-box retina MacBook Pro. It sees my wifi network--signal is max--but the base station will not accept the 100% correct password. Other devices have no trouble connecting. I'm setting it up for a PC switcher. What an embarrassmen
-
Whats the best way to get the server name in a servlet deployed to a cluster?
Hi, I have a servlet in a web application that is deployed to a cluster, just wondering what is the best way to get the name of the node that the server is running on at run time?? Thanks
-
IMovie 09 wont let me delete clips!
Checked advanced in preferences. after picking out clips to delete, there is a red band...but cannot move these to trash. since video takes so much space, need to send lots to trash...cannot..is it the software...am I doing something wrong? thanks ru
-
Prime Infrastructure issues with collection, dscp, mos, etc
We have a virtual Prime Infrastructure appliance installed. It currently shows collection status managed with warnings for several devices, i.e. Nexus 7k's, cat 3750x. cat 3850x. It is not all stacks though, most are collected accurately only a few
-
Resize my InDesign document?
My document size is 8.50 x 11 inches but I need it in 2 different sized. I also need it in 8.25 x 10.75. My document has a background image and a few other small snippets of images along with text so when I resize it everything within the document ne