Help with query - multiple where in grouped column
4 columns in table named RRID1
RRI_ID
USER_ID
PROCESS_TYPE
FUNCTION
not sure how to make this query.
Need to pull all RRI_ID's where PROCESSTYPE ='INFO' and PROCESSTYPE ='RESOLUTION'
for that RRI_ID.
so same user, same RRI_ID and 2 process records, 1 INFO and 1 RESOLUTION
so not if there is duplicate info, just if there is info and resolution.
This is what some of data looks like..
PROCESSTYPE|USER_ID|FUNCTION|RRI_ID
INFO 3668 30287 817
INFO 3748 30287 817
INFO 4714 30287 817
INFO 4875 30287 817
INFO 4882 30287 817
INFO 4885 30287 817
INFO 3748 30288 818
INFO 4714 30288 818
INFO 4716 30288 818
INFO 4882 30288 818
INFO 4885 30288 818
INFO 3668 30289 819
INFO 4716 30289 819
INFO 4875 30289 819
INFO 4882 30289 819
INFO 4885 30289 819
INFO 3668 30290 820
INFO 4716 30290 820
INFO 4875 30290 820
INFO 4882 30290 820
INFO 4885 30290 820
INFO 3668 30291 821
INFO 4714 30291 821
INFO 4716 30291 821
INFO 4875 30291 821
INFO 4882 30291 821
you will have a stroke before you hit 40That's not the point, but thanks for your concern and you'll probably end up having a stroke sooner than me if you keep asking questions this way ;)
Point is: stick to your original thread/question, keep it all together, be complete, instead of reposting and starting all over again.
It's confusing when you start a new thread, while the context of your old thread matters.
While Blu seemed to be correct, you changed the question in your previous thread after his answer and started a new one, with the same 'data'.
Hence me being a 'nit-picker', because by starting multiple threads:
- you'll get the right answer slower, maybe much slower
- we're assuming things that might be out of context, given your previous thread
etc.
Similar Messages
-
Help with query where one field is contained in another
I have two tables – t1 and t2 which matches on column a and b.
I want to create a query that displays rows where column b and do not match or column b contains data in column d.
I have created the query below but the query is still returning results where fields in column B are contained in column D.
Table
a
b
c
d
100
a
100
a
112
bcd
112
bcde
113
zzzz
113
zzzza
114
ae
114
ae
Output results expected
a
b
c
d
112
bcd
112
bcde
113
zzzz
113
zzzza
select
a
b,
c,
d
from
t1
inner
join
t2
on
t1.a
= t2.c
and
t1.b
<> t2.d
where
t1.b
not like
+ t2.d
+ '%')Try below query
select
a
b,
c,
d
from
t1
inner
join
t2
on
t1.a
= t2.c
and
t1.b
<> t2.d
A-ZSQL -
Help with query calculations (recursive)
Hi All,
I want some help with a query using a base rate and the result use in the next calculation year.
Here an example:
create table rate_type(
rate_type_id number,
rate_desc nvarchar2(50),
rate_base_year number
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
create table rates (
rate_type_id number
rate_year number,
rate_value number
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
The result of my sample data is:
2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
NAME 2012 2013 2014
Desc1 5.9149 7.1859 8.4721
Desc2 XXXX XXX XXXX
How can I do this in one select statement? Any ideas?
Thanks!Assuming you are on 11.2:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select *
from (
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
pivot (sum(result) for rate_year in (2012,2013,2014))
order by name
NAME 2012 2013 2014
Desc1 5.914908 7.2918018 8.79388703
Desc2 5.914908 7.2918018 8.79388703
SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
order by name,
rate_year
NAME RATE_YEAR RESULT
Desc1 2012 5.914908
Desc1 2013 7.2918018
Desc1 2014 8.79388703
Desc2 2012 5.914908
Desc2 2013 7.2918018
Desc2 2014 8.79388703
6 rows selected.
SQL> SY. -
Need help with turning multiple rows into a single row
Hello.
I've come across a situation that is somewhat beyond my knowledge base. I could use a little help with figuring this out.
My situation:
I am attempting to do some reporting from a JIRA database. What I am doing is getting the dates and times for specific step points of a ticket. This is resulting in many rows per ticket. What I need to do is return one row per ticket with a calculation of time between each step. But one issue is that if a ticket is re-opened, I want to ignore all data beyond the first close date. Also, not all tickets are in a closed state. I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. The database is 10.2.0.4
select jiraissue.id, pkey, reporter, summary
,changegroup.created change_dt
,dbms_lob.substr(changeitem.newstring,15,1) change_type
,row_number() OVER ( PARTITION BY jiraissue.id ORDER BY changegroup.created ASC ) AS order_row
from jiraissue
,changeitem, changegroup
,(select * from customfieldvalue where customfield = 10591 and stringvalue = 'Support') phaseinfo
where jiraissue.project = 10110
and jiraissue.issuetype = 51
and dbms_lob.substr(changeitem.newstring,15,1) in ('Blocked','Closed','Testing','Open')
and phaseinfo.issue = jiraissue.id
and changeitem.groupid = changegroup.id
and changegroup.issueid = jiraissue.id
order by jiraissue.id,change_dt
Results:
1 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2008-07-16 9:30:38 AM Open 1
2 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2008-07-16 11:37:02 AM Testing 2
3 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-06-08 9:14:52 AM Closed 3
4 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:37 AM Open 4
5 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:42 AM Open 5
6 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:50 AM Testing 6
7 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:53 AM Closed 7
8 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2008-10-03 10:26:21 AM Open 1
9 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2008-11-17 9:39:39 AM Testing 2
10 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2011-02-02 6:18:02 AM Closed 3
11 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2008-09-29 2:44:54 PM Open 1
12 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2010-05-29 4:47:37 PM Blocked 2
13 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:14:57 AM Open 3
14 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:15:32 AM Testing 4
15 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:15:47 AM Closed 5Hi,
Welcome to the forum!
StblJmpr wrote:
... I am attempting to do some reporting from a JIRA database. What is a JIRA database?
I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, if the part you don't know how to do only involves 2 tables, then jsut post a question involving those 2 tables. So you might just post this much data:
CREATE TABLE changegroup
( issueid NUMBER
, created DATE
, id NUMBER
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2008-07-16 09:30:38 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2008-07-16 11:37:02 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-06-08 09:14:52 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:37 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:42 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:50 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:53 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2008-10-03 10:26:21 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2008-11-17 09:39:39 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2011-02-02 06:18:02 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2008-09-29 02:44:54 PM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2010-05-29 04:47:37 PM', 'YYYY-MM-DD HH:MI:SS AM'), 30);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:14:57 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:15:32 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:15:47 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
CREATE TABLE changeitem
( groupid NUMBER
, newstring VARCHAR2 (10)
INSERT INTO changeitem (groupid, newstring) VALUES (10, 'Open');
INSERT INTO changeitem (groupid, newstring) VALUES (20, 'Testing');
INSERT INTO changeitem (groupid, newstring) VALUES (30, 'Blocked');
INSERT INTO changeitem (groupid, newstring) VALUES (90, 'Closed');Then post the results you want to get from that data, like this:
ISSUEID HISTORY
21191 Open (0) >> Testing (692) >> Closed
23234 Open (45) >> Testing (807) >> Closed
23977 Open (607) >> Blocked (249) >> Open (0) >> Testing (0) >> ClosedExplain how you get those results from that data. For example:
"The output contains one row per issueid. The HISTORY coloumn shows the different states that the issue went through, in order by created, starting with the earliest one and continuing up until the first 'Closed' state, if there is one. Take the first row, issueid=21191, for example. It started as 'Open' on July 16, 2008, then, on the same day (that is, 0 days later) changed to 'Testing', and then, on June 8, 2010, (692 days later), it became 'Closed'. That same issue opened again later, on September 2, 2010, but I don't want to see any activity after the first 'Closed'."
The database is 10.2.0.4That's very important. Always post your version, like you did.
Here's one way to get those results from that data:
WITH got_order_row AS
SELECT cg.issueid
, LEAD (cg.created) OVER ( PARTITION BY cg.issueid
ORDER BY cg.created
- cg.created AS days_in_stage
, ROW_NUMBER () OVER ( PARTITION BY cg.issueid
ORDER BY cg.created
) AS order_row
, ci.newstring AS change_type
FROM changegroup cg
JOIN changeitem ci ON cg.id = ci.groupid
WHERE ci.newstring IN ( 'Blocked'
, 'Closed'
, 'Testing'
, 'Open'
-- AND ... -- any other filtering goes here
SELECT issueid
, SUBSTR ( SYS_CONNECT_BY_PATH ( change_type || CASE
WHEN CONNECT_BY_ISLEAF = 0
THEN ' ('
|| ROUND (days_in_stage)
|| ')'
END
, ' >> '
, 5
) AS history
FROM got_order_row
WHERE CONNECT_BY_ISLEAF = 1
START WITH order_row = 1
CONNECT BY order_row = PRIOR order_row + 1
AND issueid = PRIOR issueid
AND PRIOR change_type != 'Closed'
ORDER BY issueid
;Combining data from several rows into one big delimited VARCHAR2 column on one row is call String Aggregation .
I hope this answers your question, but I guessed at so many things, I won't be surprised if it doesn't. If that's the case, point out where this is wrong, post what the results should be in those places, and explain how you get those results. Post new data, if necessary. -
Need help with Fluid Grid Layout and variable column balance.
I'm using the fluid grid layout. I have multiple columns that are actually fluid grid layout columns done by Dreamweaver. I'd like them to extend as high as each other (all to the maximum height of each other) within the same section. An added catch is that in the desktop layout, I have three side by side under one that takes the whole width of the page. On tablet size, it's 2x2 in a square grid. On mobile, they're vertically stacked. I'm trying to get it so that background colour and/or borders looks decent and is fully balanced, no matter which layout is hit with the fluid layout. The columns reflow, no problem. But the height of any background and/or border is variable.
Any help on fixing this?
Example at: https://music2help.thoughtburst.net/
The example doesn't have borders or colours, as it looked silly unbalanced. The music2help.css is the only one I'm modifying manually.
Love the fluid grid layout, but I need a way to make it behave decently with backgrounds/borders. Any help would be hugely appreciated!
Thanks!
mark->I tried the solution Nancy posted. It altered things, but doesn't seem to do the trick.
Just some quick background. I did HTML from 1994 through about five years ago by hand in vi on *nix systems. I learned HTML through 4.01, and never bothered with XHTML at all. I learned CSS through most of CSS2. The CSS3 and HTML5 stuff is all new to me, but it can't be that hard. I'm not exactly a novice in JS (I've done a fair bit of AJAX programming), but it's not even close to my primary language (I'm a Perl guy).
I'm "stuck on" wanting to use Fluid Grid Layouts. It's billed as one of the selling points of DW CS6, and I really like the concept and results. I just want the results embellished a little, namely with sensible identical heights on grid containers set in the same row, so that you can apply background colours, dropshadows, and borders. That's really all I want to do that it doesn't already do.
I have a test page at: http://music2help.thoughtburst.net/ that you can try with your Quick Columns. I'd be interested to know if you can get it to work.
Here's the catch, though... Resize the browser, shrinking it inwards. (I suggest Firefox, as Chrome only shrinks so far, and you won't get to Mobile width.) As you can see, on a Tablet, one of the columns that should be equal height actually moves up a row and should be equal height with the row that, on a desktop, would take the entire width of the page area. So that's like a 4-up output in printing terms. At Mobile size, the entire thing is vertical, so none of the columns should be resized.
If your product works and can accomodate these conditions, I think I would be interested in spending the $35 it costs.
Let me know? Thanks!
EDIT: Changed URL to be non-SSL. The server has multiple vhosts on it, and I keep forgetting that I don't have a cert on this new one. Sorry about that. You can just add anything to one of the the three middle columns, if you're pulling it down to test. -
Help with running multiple threads
I'm new to programming with threads. I want to know how to run
multiple threads at the same time. Particularly for making games
in Java which I'm also begining to learn. For running multiple
threads at the same time, do you have to put two run() methods
in the source? If not then how do you make two threads or more
run at the same time?
Thanks for helping.For running multiple
threads at the same time, do you have to put two run()
methods
in the source? Hi there,
Each thread is presumably performing a task. You may be performing the same task multiple times or be performing different tasks at once. Either way, each task would typically be contained within the run() method of a class. This class would either be a subclass of java.lang.Thread (extends Thread) or would be an implementation of java.lang.Runnable (implements Runnable). In either case, you would define a method with signature (public void run()...). The difference comes into play when you wish to actually perform one of these tasks. With a subclass of Thread, you would simply perform:
new MyTask().start();
With an implementation of Runnable, you would do this:
new Thread(new MyTask()).start();
This assumes you don't need to monitor the threads, won't be sending any messages to your tasks or any such thing. If that were the case, you would need to tuck away those returns to new MyTask() for later access.
In order to launch two threads simultaneously, you would have something along the lines of:
new MyTask().start();
new MyOtherTask().start();
Now it is perfectly possible that MyTask() would complete before MyOtherTask() managed to start in which case it wouldn't appear as if you had actually had multiple threads running, but for non-trivial tasks, the two will likely overlap. And of course, in a game, these tasks would likely be launched in response to user input, which means that you wouldn't have any control over when or in what order they executed.
Anyhow, it's as simple as that. You should also consider following the Java Threading trail which shows a simple example of using multiple threads. You can find it at:
http://java.sun.com/docs/books/tutorial/essential/threads/index.html
Regards,
Lynn -
Help with using multiple hard drives
Is there a way to install the OS on an "external" (expresscard SSD) drive, but have all of the library and data files on the primary hard disk? I LOVE the speed on my SSD, but it's a pain finding stuff now. Is this something a RAID configuration could help with?
mwmmartin wrote:
I have a 1 TB hard drive; but I have a 500GB and 250GB usb external hard drives.
Wouldn't it be cool if I could make the two external hard drives a RAID drive and use Time Machine to use all the 750GB of external memory to do my backups???
You can, but I would +*strongly recommend against+* it. See +Concatenated RAID+ in the Help for Disk Utility.
There are several potential problems:
Depending on how much data is on your 1 TB drive, 750 GB may not be enough to back it up. See #1 in Time Machine - Frequently Asked Questions (or use the link in *User Tips* at the top of this forum).
To set up a +Concatenated RAID+ set, both drives will be erased.
When (not if) either drive fails, you'll lose all the data on both.
Both drives must be connected any time you do a backup or want to browse your backups.
Especially with USB, if one drive wakes from sleep, or spins up, quickly enough, but the other one doesn't, the backup may fail and/or your backups may be corrupted.
For now, it looks like my only solution is to go buy a bigger external hard drive and spend more money,,,
That's your best solution +*by far.+* Anything else is taking a large risk with your backups. -
Help with query to return results from group within table?
Hi
Im a total noob, so please be gentle....!
I am looking at a table that has a WORD column and a WORD_TYPE_ID column.
Words can have the same type_id.
What I am trying to do is write a query that will return the longest word for each word_type_id.
I have been trying for hours to get this and all I seem to get is either error messages or I return the longest word in the whole WORD column.
The furthest I can get before things break down is.....
select word
from table
where
length(word) =
select
max(length(word))
from table
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
ThanksHi,
Welcome to the forum!
Here's one way:
SELECT word_type_id
, MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word
FROM table_x
GROUP BY word_type_id;If there happens to be a tie within some word_type_id (that is, 2 or more words have exactly the same length, which is the longest in that group) the expression above will return the first one, in alphabetic order. (That's what MIN means here.)
Edited by: Frank Kulash on Aug 11, 2009 1:56 PM
You almost had it.
As you noticed, you were getting the longest row in the whole table. That's because your sub-query was looking at the whole table.
If you correlate the sub-query to the row in the main table, as shown below, you can get the longest word in each group:
select word
from table m -- m for main
where length (word) = (
select max (length(word))
from table
where word_type_id = m.word_type_id -- New
); -
Need help with query for converting columns to rows
Hello,
I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
I have a table which is having multiple columns as follows:
Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
Col1 Col2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
I 0Please anybody help me in writing the query for this..Is this what you are expecting:
SQL> WITH T AS
2 (
3 SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
4 )
5 SELECT 'X' col1, X col2 FROM T
6 UNION ALL
7 SELECT 'Y' col1, Y col2 FROM T
8 UNION ALL
9 SELECT 'Z' col1, Z col2 FROM T
10 UNION ALL
11 SELECT 'A' col1, A col2 FROM T
12 UNION ALL
13 SELECT 'B' col1, B col2 FROM T
14 UNION ALL
15 SELECT 'C' col1, C col2 FROM T
16 UNION ALL
17 SELECT 'D' col1, D col2 FROM T
18 UNION ALL
19 SELECT 'E' col1, E col2 FROM T
20 UNION ALL
21 SELECT 'F' col1, F col2 FROM T
22 UNION ALL
23 SELECT 'G' col1, G col2 FROM T
24 UNION ALL
25 SELECT 'H' col1, H col2 FROM T
26 UNION ALL
27 SELECT 'I' col1, I col2 FROM T
28 /
C COL2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
C COL2
I 0
12 rows selected. -
Request help with query group by
Hi,
I have the following table structure with values
CREATE TABLE DUMMY
SR_NUMBER VARCHAR2(100 CHAR),
ASSIGNMENT_GROUP VARCHAR2(100 CHAR),
REASSIGNMENT_COUNT VARCHAR2(100 CHAR),
CREATED DATE,
CLOSED DATE,
TARGET_DATE DATE
insert into dummy values('AAA','A','1','02-OCT-11','25-OCT-11','09-OCT-11');
insert into dummy values('ABC','A','1','03-SEP-12','26-SEP-11','10-SEP-11');
insert into dummy values('AVB','A','1','02-NOV-13','25-NOV-13','09-NOV-13');
insert into dummy values('AFT','B','1','02-OCT-11','25-OCT-11','09-OCT-11');
insert into dummy values('ACS','B','1','02-JAN-12','25-JAN-12','09-JAN-12');
insert into dummy values('AVC','B','1','02-OCT-13','25-OCT-13','09-OCT-13');
insert into dummy values('AAD','B','1','02-MAR-14','25-MAR-14','09-MAR-14');
insert into dummy values('AAA','C','1','02-OCT-11','25-OCT-11','09-OCT-11');
insert into dummy values('AAA','D','1','02-JUN-11','25-JUN-11','09-JUN-11');
insert into dummy values('AAA','E','1','02-APR-12','25-APR-12','09-APR-12');
insert into dummy values('AAA','A','1','02-FEB-13','25-FEB-13','09-FEB-13');
?I have the following requirement, the output should be:
Ticket count (sr_number)
% of tickets inside DL
Number of tickets inside DL
Average cycle time (cycle time = closed date - created date)
Total cycle time (cycle time = closed date - created date)
Number of reassignments (sum)
DL - (deadline) formula is, closed date <= target_date
This should be displayed, grouped by year, then month and then by assignment group. The values should be in descending order(dates) Not sure how group by will work here.
I am able to write the basic code for the above, but group by based on year, month and assignment group is pretty confusing to me.
Can someone provide me a good code...This may not give you exactly what you want, but hopefully, it will give you something to work with:
WITH tickets AS (
SELECT TO_CHAR(created, 'YYYY') created_year,
TO_CHAR(created, 'MM') created_month,
assignment_group,
COUNT(sr_number) ticket_count,
AVG(closed - created) avg_cycle_time,
SUM(closed - created) tot_cycle_time,
COUNT(reassignment_count) reassign_count
FROM dummy
GROUP BY TO_CHAR(created, 'YYYY'),
TO_CHAR(created, 'MM'),
assignment_group
dl_tickets AS (
SELECT TO_CHAR(created, 'YYYY') created_year,
TO_CHAR(created, 'MM') created_month,
assignment_group,
COUNT(sr_number) ticket_in_dl_count
FROM dummy
WHERE closed <= target_date
GROUP BY TO_CHAR(created, 'YYYY'),
TO_CHAR(created, 'MM'),
assignment_group
SELECT t.created_year,
t.created_month,
t.assignment_group,
t.ticket_count,
NVL(dl.ticket_in_dl_count, 0) ticket_in_dl_count,
NVL(dl.ticket_in_dl_count/t.ticket_count, 0) * 100 pct_ticket_in_dl_count,
t.avg_cycle_time,
t.tot_cycle_time,
t.reassign_count
FROM tickets t,
dl_tickets dl
WHERE t.created_year = dl.created_year (+)
AND t.created_month = dl.created_month (+)
ORDER BY created_year DESC, created_month DESCEdited by: user1983440 on May 27, 2013 3:47 PM - Added reassign_count
Edited by: user1983440 on May 27, 2013 3:54 PM - Added ORDER BY -
SQL Help with change multiple columns into a single column
I am wanting to create either a new View or a new Table based on the following original table:
Original Table:
Fiscal Year
Account
Budget_Amt_January
Budget_Amt_February
Budget_Amt_March
Budget_Amt_April
<etc. for each of the 12 months)
I want the new View or Table to instead be:
New:
Fiscal_Year
Month
Account
Budget_Amount
I can't simply drop the original table, it will have to always exist since it is part of the Finance package, but for ease of reporting against I am wanting to create this new View.
Any ideas on how to go about this?
Thanks!I had to do something very similar just this week - in my case a record read from a csv into a table, then needs loading into a destination table, and the rows are columns in the csv. I went for INSERT ALL as I also had some conditions.
INSERT ALL
WHEN low1 != -998 OR high1 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 1, low1, high1 )
WHEN low2 != -998 OR high2 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 2, low2, high2 )
WHEN low5 != -998 OR high5 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 5, low5, high5 )
WHEN low6 != -998 OR high6 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 6, low6, high6 )
WHEN low7 != -998 OR high7 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 7, low7, high7 )
WHEN low8 != -998 OR high8 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 8, low8, high8 )
WHEN low9 != -998 OR high9 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 9, low9, high9 )
WHEN low10 != -998 OR high10 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 10, low10, high10 )
WHEN low11 != -998 OR high11 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 11, low11, high11 )
WHEN low12 != -998 OR high12 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 12, low12, high12 )
WHEN low13 != -998 OR high13 != -998 THEN
INTO partial_profile_temp (search_id, locus_id, low_allele, high_allele)
VALUES ( search_id, 13, low13, high13 )
SELECT * FROM bulk_search_load bst, partial_details_temp pdt
WHERE id = case_number -- only retrieves details for those records that are found in bulk_search_load
AND filename like 'NETH\_%' escape '\'
AND processed = 'N'; -
Hello, I have the following query that I'm running in Oracle SQL Developer 1.2.1
WITH group_by_4_column_results AS
(SELECT m_atschunk.employee AS employee,
SUM(CASE
WHEN
M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as rolloffs,
M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
FROM M_ATSCHUNK
group by employee, infractionDate, rolloffDaysCount
SELECT g4.*,
SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
FROM group_by_4_column_results g4
It will output the key elements of what I need. But where it sums up the 'total_rolloffs', I need to add that number back into the infractiondate column. Any help would be greatly appreciated.
CREATE TABLE M_ATSCHUNK
(EMPLOYEE varchar(50),
ROLLOFFDAYSCOUNT varchar(3),
INFRACTIONDATE date)
INSERT INTO M_ATSCHUNK (EMPLOYEE, ROLLINGOFFDAYSCOUNT, INFRACTIONDATE)
VALUES ('PHIL','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/02 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/03 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/04 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/05 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/02/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/03/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss')))Phil3061 wrote:
I need to add that number back into the infractiondate column.Well, in general you need to use UPDATE or better MERGE. Howebver, your data sample does not show any rollofs:
SQL> SELECT * FROM M_ATSCHUNK;
EMPLOYEE ROL INFRACTIO
PHIL YES 01-JAN-10
PHIL YES 02-JAN-10
PHIL YES 03-JAN-10
PHIL YES 04-JAN-10
PHIL YES 05-JAN-10
PHIL NO 01-FEB-10
PHIL NO 01-MAR-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI NO 01-JAN-10
EMPLOYEE ROL INFRACTIO
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
14 rows selected.
SQL> WITH group_by_4_column_results AS
2 (SELECT m_atschunk.employee AS employee,
3 SUM(CASE
4 WHEN
5 M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as
rolloffs,
6 M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
7 FROM M_ATSCHUNK
8 group by employee, infractionDate, rolloffDaysCount
9 )
10 SELECT g4.*,
11 SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
12 FROM group_by_4_column_results g4
13 /
EMPLOYEE ROLLOFFS INFRACTIO TOTAL_ROLLOFFS
NIKI 0 01-JAN-11 0
NIKI 0 01-JAN-11 0
PHIL 0 01-JAN-11 0
PHIL 0 02-JAN-11 0
PHIL 0 03-JAN-11 0
PHIL 0 04-JAN-11 0
PHIL 0 05-JAN-11 0
PHIL 0 01-FEB-11 0
PHIL 0 01-MAR-11 0
9 rows selected.
SQL> So adjust data sample and based on it tell us what are the expected results.
SY. -
Help with exercise on joins and group by
Could someone help me with an exercise I'm working on? This isn't "homework", per se, as it's not an assignment, I'm just doing my own personal research.
I have the usual tables "DEPARTMENT" and "EMPLOYEE", with the following columns:
Department:
* NAME
* ID
Employee:
* SSN
* NAME
* DEPT_ID
* SALARY
I'm able to build a query that summarizes the departments with total employee salary > 30000, like this:
select dept_id, sum(salary) from employee group by dept_id having sum(salary) > 30000;
What I'd like to extend this to is a summary of departments with total employee salary > 30000 OR no employees at all (or total salary = 0, conceptually).
I imagine this will include a left outer join, but I can't get this to work.http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1670
http://www.oracle.com/technology/products/oracle9i/daily/oct10.html
http://www.dba-oracle.com/t_sql99_with_clause.htm
http://www.psoug.org/reference/with.html
WITH clause is used for reusability of sub queries within a query. And in this case it is useful to build the query without having to create a table with data and show the results.
SQL> select 1 dept_id, 'ABC' dept_name from dual;
DEPT_ID DEP
1 ABCHere I am selecting some static values from dual table where I say I want 1 as dept_id and its name as ABC.
SQL> select 1 dept_id, 'ABC' dept_name from dual union all
2 select 2 dept_id, 'XYZ' dept_name from dual union all
3 select 3 dept_id, 'MNO' dept_name from dual;
DEPT_ID DEP
1 ABC
2 XYZ
3 MNOIn the above query I am selecting 3 static department ids and names in three separate queries and combining them using union all. Thus I am getting them as three rows.
SQL> with dept as(
2 select 1 dept_id, 'ABC' dept_name from dual union all
3 select 2 dept_id, 'XYZ' dept_name from dual union all
4 select 3 dept_id, 'MNO' dept_name from dual )
5 --
6 select * from dept;
DEPT_ID DEP
1 ABC
2 XYZ
3 MNOHere, In the above query, I just named the previous query as "dept" and I am just selecting all from "dept". You can say it something like a virtual table which has data based on a query, that can be reused in other/main query. The limitations, uses and elaborate descriptions are available in the links I provided. -
Need help with query joining several tables into a single return line
what i have:
tableA:
puid, task
id0, task0
id1, task1
id2, task2
tableB:
puid, seq, state
id0, 0, foo
id0, 1, bar
id0, 2, me
id1, 0, foo
id2, 0, foo
id2, 1, bar
tableC:
puid, seq, date
id0, 0, 12/21
id0, 1, 12/22
id0, 2, 12/22
id1, 0, 12/23
id2, 0, 12/22
id2, 1, 12/23
what i'd like to return:
id0, task0, 12/21, 12/22, 12/22
id1, task1, 12/23, N/A, N/A
id2, task2, 12/22, 12/23, N/A
N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
id0, task0, 12/21
id0, task0, 12/22
id0, task0, 12/23
id1, task1, 12/23
is this possible fairly easily?
Edited by: user9979830 on Mar 29, 2011 10:53 AM
Edited by: user9979830 on Mar 29, 2011 10:58 AMHi,
Welcome to the forum!
user9979830 wrote:
what i have:...Thanks for posting that so clearly!
Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
CREATE TABLE tablea
( puid VARCHAR2 (5)
, task VARCHAR2 (5)
INSERT INTO tablea (puid, task) VALUES ('id0', 'task0');
INSERT INTO tablea (puid, task) VALUES ('id1', 'task1');
INSERT INTO tablea (puid, task) VALUES ('id2', 'task2');
CREATE TABLE tablec
( puid VARCHAR2 (5)
, seq NUMBER (3)
, dt DATE -- DATE is not a good column name
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 0, DATE '2010-12-21');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 1, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 2, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id1', 0, DATE '2010-12-23');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 0, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 1, DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
It doesn't look like tableb plays any role in this problem, so I didn't post it.
Explain how you get the results from that data. For example, why do you want this row in the results:
PUID TASK DT1 DT2 DT3
id0 task0 12/21/2010 12/22/2010 12/22/2010rather than, say
PUID TASK DT1 DT2 DT3
id0 task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
WITH got_r_num AS
SELECT puid
, dt
, ROW_NUMBER () OVER ( PARTITION BY puid
ORDER BY seq -- and/or dt
) AS r_num
FROM tablec
-- WHERE ... -- If you need any filtering, put it here
SELECT a.puid
, a.task
, MIN (CASE WHEN r.r_num = 1 THEN r.dt END) AS dt1
, MIN (CASE WHEN r.r_num = 2 THEN r.dt END) AS dt2
, MIN (CASE WHEN r.r_num = 3 THEN r.dt END) AS dt3
, MIN (CASE WHEN r.r_num = 4 THEN r.dt END) AS dt4
FROM tablea a
JOIN got_r_num r ON a.puid = r.puid
GROUP BY a.puid
, a.task
ORDER BY a.puid
;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
Here's the output I got from the query above:
PUID TASK DT1 DT2 DT3 DT4
id0 task0 12/21/2010 12/22/2010 12/22/2010
id1 task1 12/23/2010
id2 task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
For various ways to deal with a variable number of pivoted coolumns, see the following thread:
PL/SQL
This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
PL/SQL
If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one. -
Help with query to return last possible value
Can someone please help me create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2(10),
DEPTID VARCHAR2(10),
CHARGENUMBER NUMBER(10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
Would like to return the following:
A, B, 2
C, D, 4
In other words, I would like to return the last possible CHARGENUMBER for FACID and DEPTID.
The table does not have any indexes and it gets loaded from a spreadsheet in that order.
Thanks so much!amazongirl wrote:
Can someone please help me create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2(10),
DEPTID VARCHAR2(10),
CHARGENUMBER NUMBER(10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
Would like to return the following:
A, B, 2
C, D, 4
In other words, I would like to return the last possible CHARGENUMBER for FACID and DEPTID.
The table does not have any indexes and it gets loaded from a spreadsheet in that order.
Thanks so much!Hi girl from amazon,
I hope you give me a note because I answered for a lot of questions and nobody aprecieted that. If you don't me a little point I wil leave this forum because isn't so funny to work for nothing.
You are my last chance to stay here!
FACID DEPTID CHARGENUMBER
A B 1
A B 2
C D 3
C D 4
HR: XE > select x.FACID, x.DEPTID , x.CHARGENUMBER from tableA x,
2 (select DEPTID, FACID, max(CHARGENUMBER) max_val from tableA
3 group by DEPTID, FACID ) y
4 WHERE x.DEPTID = y.DEPTID and
5 x.FACID = y.FACID and
6 x.CHARGENUMBER =max_val;
FACID DEPTID CHARGENUMBER
A B 2
C D 4Regards,
Ion
Maybe you are looking for
-
How to print lables in SAP SCRIPT
Hi all, Here i have a requirement in SAP Script How to print the lables instead of Hard coding the field Description. Please help me how to do. Regards Raghava
-
Hi, we started customizing the IC Webclient trough profiles (as described in the "Consultant's Cookbook for IC Webclient CRM 4.0", Chapter 3). Assigning profiles seem to work, but the profile xml-tags in the profile ("<ControllerReplacements>") don't
-
Can I use an interactive PDF created in InDesign in Muse?
If I make an interactive PDF in InDesign can I then import it into Muse?
-
How to display a StyledDocument? (not in JTextComponent)
I have read the following tutorials and relevant API's from the Swing Connection: Text overview: http://java.sun.com/products/jfc/tsc/articles/text/overview/index.html Text attributes: http://java.sun.com/products/jfc/tsc/articles/text/attributes/ind
-
Hi, There s a std transaction F.27(RFKORK00) which we need to run to get Customer Statement. in this program, it uses a SUBMIT ( SAP140 ) which in turn uses a submit ( RFKORD11 ). i m using a customised program in place of RFKORD11. in this program i