Please help urgent in PL/SQL or SQL
I have table like
TIMESTAMP SID
11/12/2008 1:25:02 PM 10
11/12/2008 1:25:02 PM 20
11/12/2008 1:25:02 PM 30
11/12/2008 1:30:02 PM 10
11/12/2008 1:30:02 PM 40
11/12/2008 1:35:00 PM 40
11/12/2008 1:35:00 PM 50
11/12/2008 1:35:00 PM 60
11/12/2008 1:35:00 PM 70
You can assume that for the first timestamp entry, all SID are new.
eg:1.25.02timestamp new sid(10,20,30)
compare that sid with next timestamp of sid
eg:1.25.02timestamp has sid 10 and 1.30.02timestamp has sid 10 so existing sid is 10
1.30.2timestamp don't have 20,30 compare with 1.25.02 timestamp so sid 20,30 are deleted
1.30.2timestamp have 40 so newsid is 40
then compare the secondtimestamp(1.30.2timestamp ) to thirdtimestamp(1:35:00)
NOTE: LOOK THREAD :nee help in PL/SQL or SQL
THIS QUERY GIVES LIKE:
TIMESTAMP New SID Existing SID Deleted SID
11/12/2008 1:25:02 PM 3 0 0
11/12/2008 1:30:02 PM 1 1 2
11/12/2008 1:35:00 PM 3 1 1
BUT EXPECTED OUTPUT LIKE(I WANT LIKE)
TIMESTAMP New SID Existing SID Deleted SID
11/12/2008 1:25:02 PM 10,20, 30 0 0
11/12/2008 1:30:02 PM 40 10 20, 30
11/12/2008 1:35:00 PM 50,60, 70 40 10
ANYBODY HELP PLEASE
alter session set nls_date_format = 'MM/DD/YYYY HH:MI:SS PM'
with t as (
select '11/12/2008 1:25:02 PM' tstamp,10 sid from dual union all
select '11/12/2008 1:25:02 PM',20 from dual union all
select '11/12/2008 1:25:02 PM',30 from dual union all
select '11/12/2008 1:30:02 PM',10 from dual union all
select '11/12/2008 1:30:02 PM',40 from dual union all
select '11/12/2008 1:35:00 PM',40 from dual union all
select '11/12/2008 1:35:00 PM',50 from dual union all
select '11/12/2008 1:35:00 PM',60 from dual union all
select '11/12/2008 1:35:00 PM',70 from dual
select tstamp,
ltrim(replace(sys_connect_by_path(case new when 1 then sid else -1 end,','),',-1'),',') "New SID",
ltrim(replace(sys_connect_by_path(case existing when 1 then sid else -1 end,','),',-1'),',')"Existing SID",
ltrim(replace(sys_connect_by_path(case deleted when 1 then sid else -1 end,','),',-1'),',')"Deleted SID"
from (
select tstamp,
sid,
grp,
new,
existing,
deleted,
row_number() over(partition by grp order by sid nulls last) rn
from (
select tstamp,
sid,
-- group number based on timestamp
dense_rank() over(order by tstamp) grp,
-- Check if sid is new sid (not present in previous group)
case when lag(tstamp) over(partition by sid order by tstamp) is null then 1 else 0 end new,
-- Check if sid is existing sid (present in previous group)
case when lag(tstamp) over(partition by sid order by tstamp) is null then 0 else 1 end existing,
0 deleted
from t
union all
-- List of sid's not present in a group but present in a previous group
select null tstamp,
sid,
grp + 1 grp,
0 new,
0 existing,
1 deleted
from (
select sid,
grp,
-- Check if sid is present in next group (1 - present, 0 - not present).
case lead(grp) over(partition by sid order by grp)
when grp + 1 then 1
else 0
end in_next_grp,
-- last group number
max(grp) over() max_grp
from (
select tstamp,
sid,
-- group number based on timestamp
dense_rank() over(order by tstamp) grp
from t
where in_next_grp = 0
and grp < max_grp
where connect_by_isleaf = 1 -- we are only interested in a leaf row which represents complete branch
start with rn = 1 -- start with first row in a group
connect by rn = prior rn + 1 and grp = prior grp -- traverse through each sid in a group including deleted
order by tstamp
SQL> alter session set nls_date_format = 'MM/DD/YYYY HH:MI:SS PM'
2 /
Session altered.
SQL> with t as (
2 select '11/12/2008 1:25:02 PM' tstamp,10 sid from dual union all
3 select '11/12/2008 1:25:02 PM',20 from dual union all
4 select '11/12/2008 1:25:02 PM',30 from dual union all
5 select '11/12/2008 1:30:02 PM',10 from dual union all
6 select '11/12/2008 1:30:02 PM',40 from dual union all
7 select '11/12/2008 1:35:00 PM',40 from dual union all
8 select '11/12/2008 1:35:00 PM',50 from dual union all
9 select '11/12/2008 1:35:00 PM',60 from dual union all
10 select '11/12/2008 1:35:00 PM',70 from dual
11 )
12 select tstamp,
13 ltrim(replace(sys_connect_by_path(case new when 1 then sid else -1 end,','),',-1'),',') "New SID",
14 ltrim(replace(sys_connect_by_path(case existing when 1 then sid else -1 end,','),',-1'),',')"Existing SID",
15 ltrim(replace(sys_connect_by_path(case deleted when 1 then sid else -1 end,','),',-1'),',')"Deleted SID"
16 from (
17 select tstamp,
18 sid,
19 grp,
20 new,
21 existing,
22 deleted,
23 row_number() over(partition by grp order by sid nulls last) rn
24 from (
25 select tstamp,
26 sid,
27 -- group number based on timestamp
28 dense_rank() over(order by tstamp) grp,
29 -- Check if sid is new sid (not present in previous group)
30 case when lag(tstamp) over(partition by sid order by tstamp) is null then 1 else 0 end new,
31 -- Check if sid is existing sid (present in previous group)
32 case when lag(tstamp) over(partition by sid order by tstamp) is null then 0 else 1 end existing,
33 0 deleted
34 from t
35 union all
36 -- List of sid's not present in a group but present in a previous group
37 select null tstamp,
38 sid,
39 grp + 1 grp,
40 0 new,
41 0 existing,
42 1 deleted
43 from (
44 select sid,
45 grp,
46 -- Check if sid is present in next group (1 - present, 0 - not present).
47 case lead(grp) over(partition by sid order by grp)
48 when grp + 1 then 1
49 else 0
50 end in_next_grp,
51 -- last group number
52 max(grp) over() max_grp
53 from (
54 select tstamp,
55 sid,
56 -- group number based on timestamp
57 dense_rank() over(order by tstamp) grp
58 from t
59 )
60 )
61 where in_next_grp = 0
62 and grp < max_grp
63 )
64 )
65 where connect_by_isleaf = 1 -- we are only interested in a leaf row which represents complete branch
66 start with rn = 1 -- start with first row in a group
67 connect by rn = prior rn + 1 and grp = prior grp -- traverse through each sid in a group including deleted
68 order by tstamp
69 /
TSTAMP New SID Existing SID Deleted SID
11/12/2008 1:25:02 PM 10,20,30
11/12/2008 1:30:02 PM 40 10 20,30
11/12/2008 1:35:00 PM 50,60,70 40 10
SQL> SY.
Similar Messages
-
Please help me convert the SQL to HQL
select
count(*) as col_0_0_
from
edu.hr_people_all hrpeopleal0_
left outer join
edu.conditions_journal conditions1_
on hrpeopleal0_.people_id=conditions1_.people_id
and conditions1_.personal_number like '%'
where
hrpeopleal0_.status=11Hibernate version: 3
HQL as I 've done
FROM PMSProjectsORO pjt LEFT JOIN PMSChecklistORO pcl
ON pjt.projectId = pcl.projectId order by
pjt.projectCode ascHQL is probably incorrect.
Try this:
FROM
PMSProjectsORO pjt
LEFT JOIN
PMSChecklistORO pcl
ORDER BY
pjt.projectCode asc>
Original SQL for MSQL5:
FROM PMSProject LEFT JOIN PMSCheckList ON
PMSProject.PROJECT_ID = PMSCheckList.PROJECT_ID order
by PMSProject.PROJECT_CODE desc
Name and version of the database you are using:
MYSQL 5
Please help me convert the sql to hql since what i
've done is throwing error like unexpected token...
Please reply ASAPLet me know if that's better.
% -
PASSWORD FOR FLODERS PLEAse HELP URGENT
HI ALL
please tell me the method of implementing password
provision for some folders/files in the system.
it should ask for password authentification before
opening when i click on the folder.
please help urgent
thanks
belurHi Swaroopba,
It can be very well done thru Form based Authentication.
For eg let me explain with respect to Tomcat.
Go to
$TOMCAT_HOME/webapps/examples/WEB-INF directory.
Please add the following code in it.
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area </web-resource-name>
<!-- Define the context URL's to be protected -->
<url-pattern>/jsp/security/protected</url-pattern>
</web-resource-collection>
</security-constraint>
Please add the following code in it. And you have to specify the roles for it.
I hope this will be helpful for you.
Or if you want it in an application, please let me know.
Thanks
Bakrudeen -
I want to buy an in-app purchase but i don`t remember my security questions and i cant access my recovery email either, what can i do? i have 100$ on my account and cant use it because of that problem, please help URGENT
If you have a rescue email address on your account then you can use that - follow steps 1 to 5 half-way down this page will give you a reset link on your account : http://support.apple.com/kb/HT5312
If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will need to contact Support in your country to get the questions reset : http://support.apple.com/kb/HT5699 -
please help URGENT : Chinese handwriting doesn't seem to work on Lion OSX. the handwriting trackpad appears but anything i write in Chinese doesn't appear in word, chrome,..... HELP PLEASE
And in system prefs/language and text/input languages, simplified chinese and traditional chinese are ticked as usual with handwriting options on !!!!Please search the forum for "chinese" to find the many other earlier posts about your issue, like
https://discussions.apple.com/message/15746805#15746805 -
I bought an iphone 5 from apple store in Geneva to use in Turkey. But it is sim-locked. What can I do now. Please help urgently.
Return it to the store where you purchased & get your money back. Either that, or call the store. No one here can help you, as there is no one from Apple here.
-
Hi everyone, I�m having problems with Java Mail, I have just installed it along with the java activation framework, they are located in the following directories:
JavaMail: C:\jdk1.3.1\lib\javamail-1_2[1]
Java activation framework: C:\jdk1.3.1\lib\jaf1_0_1[1]
I have the classpath set as: C:\jdk1.3.1\lib\mail.jar;C:\jdk1.3.1\lib\activation.jar
When I try to compile the sample code provided with these packages, msgsend.java using Jbuilder 2 I get the following errors:
Error (36): cannot access directory javax\mail.
Error (37): cannot access directory javax\mail\internet.
Error (209): class message not found in class msgsend.
Error (210): class MessagingException not found in class msgsend
Error (134): class Session not found in class msgsend
Error (134): variable Session not found in class msgsend
Error (139): class Message not found in class msgsend
Error (139): class MimeMessage not found in class msgsend
Error (141): class InternetAddress not found in class msgsend
Error (145): cannot access class Message.RecipientType;neither class nor source found for Message.RecipientType.
Error (146): Variable InternetAddress not found in class msgsend
Error (148): cannot access class Message.RecipientType;neither class nor source found for Message.RecipientType.
Error (149): Variable InternetAddress not found in class msgsend
Error (151): cannot access class Message.RecipientType;neither class nor source found for Message.RecipientType.
Error (152): Variable InternetAddress not found in class msgsend
Error (162): Variable Transport not found in class msgsend
Error (170): class Store not found in class msgsend
Error (172): class URLName not found in class msgsend
Error (172): class URLName not found in class msgsend
Error (189): class Folder not found in class msgsend
Error (195): Variable Folder not found in class msgsend
Error (197): class Message not found in class msgsend
Error (197): class Message not found in class msgsend
If I try to use another Java package to compile it I get even more errors (52), I cannot compile it by using the Javac command line compiler, it just says �Bad command or file name�.
Can anyone tell me Why this is happening and how I might be able to fix it please, I need to start learning Java Mail quickly but at the moment I can�t even begin to do this until I can understand how to get this sample code to work.
Thanks Everyone
NoelFirst of all... don't post with topics like "Please Help - Urgent". The topic is supposed to reflect what the question is about.
Secondly... think for a second. If mail.jar is in C:\jdk1.3.1\lib\javamail-1_2[1]... why are you with your classpath saying that mail.jar is in C:\jdk1.3.1\lib ?
You classpath is supposed to point directly at you jar-files.
/Michael -
how to download garageband old version? i mean version 1.0 to install it on iphone 4s with ios 6.0.1??? please help urgently, how to download garageband old version? i mean version 1.0 to install it on iphone 4s with ios 6.0.1??? please help urgently
I did this a few weeks ago to be sure it was going to work for a young person I was giving my ipod to. Then I reset the information for her and now it will not load. Very sad. She is so talented and she really needs this. Anyone know?
-
I received an iCloud backup notification on my ipad mini but tapping "OK" does not remove it and therefore I am unable to do any activity on my ipad mini. please help urgent.??
Have you tried a reset ? Press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider if it appears), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.
-
Please Help Urgently to refresh the report on the change in data
We want to refresh report at runtime for the Drill Down report if any user changes the Data. We changes the data from the form which is called from the report and we want to this effect on the report on the prompt.
Is there any method to close the report while it is in the queue of Background Engine? Can we refresh the report ? Please help urgently.
Thanks in Advance.Pritesh,
Reports goes out to the database and fetches the data (not a snapshot) and returns the information, formats it and displays it. The only way to refresh, is to rerun the report.
If your are running from the server, you need to make sure you are not fetching from cache (you determine this from destype and set the life of the cache in the servername.ora file).
I am unaware of any way to programatically close the report once displayed. The user must take action to close the report (unless you call the operating system to kill the display). When you rerun the report from Oracle Forms, you will get fresh data.
Regards,
The Oracle Reports Team jls -
I have lost my iphone 4 just an hour ago... i need to delete my personal photos from it. PLease help urgently.. Thanks
If you had find my iphone enabled follow the steps in the article below:
http://support.apple.com/kb/ph2701 -
Starting tomcat problem, please help urgent
I installed jwsdp on windowsXP . The log file gives this following error when i try to start tomcat:
java.util.zip.ZipException: Access is denied
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:138)
at java.util.jar.JarFile.<init>(JarFile.java:80)
at org.apache.catalina.loader.StandardClassLoader.addRepositoryInternal(StandardClassLoader.java:1081)
at org.apache.catalina.loader.StandardClassLoader.<init>(StandardClassLoader.java:200)
at org.apache.catalina.startup.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:202)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:141)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
Bootstrap: Class loader creation threw exception
java.lang.IllegalArgumentException: addRepositoryInternal: java.util.zip.ZipException: Access is denied
at org.apache.catalina.loader.StandardClassLoader.addRepositoryInternal(StandardClassLoader.java:1109)
at org.apache.catalina.loader.StandardClassLoader.<init>(StandardClassLoader.java:200)
at org.apache.catalina.startup.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:202)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:141)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
PLEASE HELP ,URGENTLY NEEDED TO SHOW SOME WORK ON THIS.
THANKS
jimHi,
I have a similar problem, i try to deploy a JAR file built on AIX 5.2 platform (jvm 14.1) into Tomcat 5.5.7 running on Windows platform when i try start Tomcat it's fail with the fellowing message
SEVERE: Error deploying web application directory usi
java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:299)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:238)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:73)
at java.util.jar.JarInputStream.<init>(JarInputStream.java:58)
at java.util.jar.JarInputStream.<init>(JarInputStream.java:43)
at org.apache.catalina.util.ExtensionValidator.getManifest(ExtensionValidator.java:368)
at org.apache.catalina.util.ExtensionValidator.validateApplication(ExtensionValidator.java:187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3942)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:872)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1106)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1019)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1011)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409) -
I've added a pdf to itunes and i want to change it so its visible with an album (digital booklet). But for some reason, when i click get info, its all greyed out and the little box for read only is unticked. please help - urgent! thanks
Hi
My first thoughts are
• iMovie ill behaving - Trash the iMovie pref file - use to set things right
• in reg. to Photos - Did You change iPhoto Photo Library - Then iMovie get's lost as it peeks into iPhoto on start up to see where photos are stored. Set iPhoto back to first Photo Library (when iMovie is not running) then start iMovie.
Yours Bengt W -
Please help: problem configuring a SQL server datasource in Websphere.
I am using Rational Developer 6 and its integrated testing server (websphere v6). When configuring a data source for SQL server, I did the following steps in admin console of the test server:
1. Created a JDBC provider, using WebSphere embedded ConnectJDBC driver for MS SQL Server;
2. Created a datasource under the previously created JDBC provider, filled in the server name, DB name and port number (1433 for SQL server);
3. Created a J2C authentication alias that has the login info of SQL server;
4. Assigned the created J2C alias to both component and container managed authentication alias;
However, when I click "Test Connection", it always gets back to me with an error "java.lang.Exception: java.sql.SQLException: [IBM][SQLServer JDBC Driver]Error establishing socket. Connection refused: connectDSRA0010E: SQL State = 08001, Error Code = 0.".
My ultimate goal is to configure a SQL server datasource so that I can configure Kodo to use this datasource.
Can some one please help? Thanks in advance.Try this:
http://www-1.ibm.com/support/docview.wss?uid=swg21210871
I am yet to test this. I am going to download latest SP for SQL Server 2000 and install it. I hope it will do the magic. -
Please help me with this SQL query
I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
The three tables are as below
<pre>
Country
location_id country
loc1 Spain
loc2 England
loc3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA
</pre>
<pre>
User
user_id location_id
u1 loc1
u2 loc1
u3 loc2
u4 loc2
u5 loc1
u6 loc3
</pre>
<pre>
Post
post_id user_id
p1 u1
p2 u1
p3 u2
p4 u3
p5 u1
p6 u2
</pre>
I am trying to write an SQL query - for each country of users, display the average number of posts
I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
Thanks.select
country.country,
count(*) Totalpostspercountry,
count(distinct post.user_id) Totaldistincuserspercountry,
count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
from
country, muser, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
group by country.country
The output is like this for your sample data - hope this is what you were looking for :)
COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
England,1,1,1,
Spain,5,2,2.5,
Maybe you are looking for
-
Hello, I cannot seem to create PDF files from Preview, or by printing files. Simply, nothing happens when PDF is chosen from the print menu, in Safari. Opening the would-be PDF in Preview, and printing causes the Preview application to freeze. Below
-
I've been searching for this answer for quite some time now and I'm unable to find it on this site. Maybe my search skillz are slacking, or maybe I'm tired.. I created a UI with some textboxes. I want to insert into my MS Access Database what I wrote
-
Hi Experts, I need a keyfig "Avg. Pay Days" which is a formula of avg(Days w/o payment) for FI-AP report in BI, which gets data from FBL1N report in r/3. Avg. Pay Days = avg(Days w/o payment) Can anyone pls help me how to get the above value of count
-
Cann't access oracle 9i with thin jdbc and applet
Hi.. I write thin jdbc applet and application programs.. application programs works well.. but applet cann't connect... error messages below.. access denied (java.util.PropertyPermission oracle.jserver.version read) web server and dbms server are on
-
InfoView - Default view latest instance possible?
Hi, I have an issue with InfoView, and the opening/viewing of Desktop Intelligence reports. The report I am talking about is scheduled on a daily basis (each night) so users don't have to refresh it every time they open it. To view it via InfoView, t