Need help to design a query to return the lines as shown below
Hi all
I have say emp table. I am trying to generate an extra column where it will contain for the 3 first lines say I generates 1, then 3 rows I will generate 2 like that.
I'm checking a number of different options, but I do not get a clear idea on how to generate.
Grateful if someone can throw an idea about it.
Thank you
MK.
Hello
Why do you want 'SMITH', 'ALLEN' and 'QUARTER' for are given the number 1? Why not, say, "SMITH", "JONES" and "MILLER"? If you use words like 'first' or 'next' in your explanation, explain what they mean, since there are many different ways to sort the lines.
Maybe you care even with 3 employees are assigned the number 1, so long as exactly 3 get number 1, another 3 get number 2, and so on.
I'm guessing you want something like this:
SELECT CEIL (ROW_NUMBER () OVER (ORDER BY empno)
/ 3
) AS r_num
empno, ename, job, mgr, hiredate, sal, comm, deptno
WCP
ORDER BY empno
;
ROWNUM is a keyword from Oracle, this is not a column name good. I used r_num instead. (According to your limit, you can use ROWNUM to get r_num.)
Tags: Database
Similar Questions
-
Need help with a SQL qurey that returns multiple lines for a record?
I have the following query where I use a WHEN clause CASES to determine the date of a change that starts with 'FRLO' on day 1 - day14 of the pay period. It works fine if a folder schedule with a day that begins "FRLO", but if more than one day is "FRLO" then it only returns the first day he finds and not others. Is there a way to get the query to return a ron for every day 1-14 that begins "FRLO"? System if Oracle 11 G
The order of the results is not important, because this is part of a larger query that orders the results.
Thanks in advance for any help,
George
---------------------------------------------------------------------------------------------------------------------------------
SELECT s.empid,
CASE
A SUPERIOR TIME (SUBSTR (s.Day1, 0, 4)) = "FRLO".
THEN
pp.startpp
A SUPERIOR TIME (SUBSTR (s.Day2, 0, 4)) = "FRLO".
THEN
pp.startpp + 1
A SUPERIOR TIME (SUBSTR (s.Day3, 0, 4)) = "FRLO".
THEN
pp.startpp + 2
A SUPERIOR TIME (SUBSTR (s.Day4, 0, 4)) = "FRLO".
THEN
pp.startpp + 3
A SUPERIOR TIME (SUBSTR (s.Day5, 0, 4)) = "FRLO".
THEN
pp.startpp + 4
A SUPERIOR TIME (SUBSTR (s.Day6, 0, 4)) = "FRLO".
THEN
pp.startpp + 5
A SUPERIOR TIME (SUBSTR (s.Day7, 0, 4)) = "FRLO".
THEN
pp.startpp + 6
A SUPERIOR TIME (SUBSTR (s.Day8, 0, 4)) = "FRLO".
THEN
pp.startpp + 7
A SUPERIOR TIME (SUBSTR (s.Day9, 0, 4)) = "FRLO".
THEN
pp.startpp + 8
A SUPERIOR TIME (SUBSTR (s.Day10, 0, 4)) = "FRLO".
THEN
pp.startpp + 9
A SUPERIOR TIME (SUBSTR (s.Day11, 0, 4)) = "FRLO".
THEN
pp.startpp + 10
A SUPERIOR TIME (SUBSTR (s.Day12, 0, 4)) = "FRLO".
THEN
pp.startpp + 11
A SUPERIOR TIME (SUBSTR (s.Day13, 0, 4)) = "FRLO".
THEN
pp.startpp + 12
A SUPERIOR TIME (SUBSTR (s.Day14, 0, 4)) = "FRLO".
THEN
pp.startpp + 13
END
StartDate,
StartTime, NULL,
Time NULL terminator,
8 hours,
0 minutes
Time S
JOIN THE
payperiods pp
ON pp.periodid = s.periodid
WHERE SUPERIOR (SUBSTR (s.Day1, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day2, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day3, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day4, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day5, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day6, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day7, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day8, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day9, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day10, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day11, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day12, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day13, 0, 4)) = "FRLO".
OR SUPERIOR (SUBSTR (s.Day14, 0, 4)) = "FRLO";
----------------------------------------------------------------------------------------------
OUTPUT CURRENT
EMPID STARTDATE, STARTTIME ENDTIME HOURS MINUTES
753738, 25/03/2013, 8, 0
753740, 25/03/2013, 8, 0
753748, 25/03/2013, 8, 0
DESIREE OUTPUT
EMPID STARTDATE, STARTTIME ENDTIME HOURS MINUTES
753738, 25/03/2013, 8, 0
753740, 25/03/2013, 8, 0
753748, 25/03/2013, 8, 0
753738, 26/03/2013, 8, 0
753740, 26/03/2013, 8, 0
753740, 28/03/2013, 8, 0
753748, on 01/01/2013, 8, 0
753738, on 03/04/2013, 8, 0
753748, on 03/04/2013, 8, 0
-----------------------------------------------------------------------------------------------
CREATE THE TABLE PROGRAMS
(
SCHEDULEID NUMBER (12) NOT NULL,
EMPID NUMBER (12) NOT NULL,
PERIODID VARCHAR2 (6 BYTE) NOT NULL,
AREAID NUMBER (12) NOT NULL,
DAY1 VARCHAR2 (50 BYTE),
DAY 2 VARCHAR2 (50 BYTE).
DAY 3 VARCHAR2 (50 BYTE).
DAY4 VARCHAR2 (50 BYTE),
DAY5 VARCHAR2 (50 BYTE),
DAY6 VARCHAR2 (50 BYTE),
DAY 7 VARCHAR2 (50 BYTE).
JOUR8 VARCHAR2 (50 BYTE),
DAY9 VARCHAR2 (50 BYTE),
DAY10 VARCHAR2 (50 BYTE),
DAY 11 VARCHAR2 (50 BYTE).
DAY12 VARCHAR2 (50 BYTE),
J13 VARCHAR2 (50 BYTE),
DAY14 VARCHAR2 (50 BYTE),
NOPTIND1 INTEGER DEFAULT 0,
NOPTIND2 INTEGER DEFAULT 0,
NOPTIND3 INTEGER DEFAULT 0,
NOPTIND4 INTEGER DEFAULT 0,
NOPTIND5 INTEGER DEFAULT 0,
NOPTIND6 INTEGER DEFAULT 0,
NOPTIND7 INTEGER DEFAULT 0,
NOPTIND8 INTEGER DEFAULT 0,
NOPTIND9 INTEGER DEFAULT 0,
NOPTIND10 INTEGER DEFAULT 0,
NOPTIND11 INTEGER DEFAULT 0,
NOPTIND12 INTEGER DEFAULT 0,
NOPTIND13 INTEGER DEFAULT 0,
NOPTIND14 INTEGER DEFAULT 0
);
CREATE TABLE PAYPERIODS
(
PERIODID VARCHAR2 (6 BYTE) NOT NULL,
DATE OF STARTPP,
DATE OF ENDPP
);
Insert in CALENDARS
(SCHEDULEID, EMPID, PERIODID, DAY1, AREAID
DAY 2, DAY 3, DAY 4, DAY5 DAY6.
DAY7 JOUR8, DAY9, DAY10, DAY 11,.
J13, DAY14 DAY12, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693744, 753738, '082013' 2167, 'X')
"FRLO < 1530 > ', ' < 1530 FRLO > ', '1530', '1530', '1530',
'X', 'X', '1530', '1530', 'FRLO ',.
"1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
(0, 0);
Insert in CALENDARS
(SCHEDULEID, EMPID, PERIODID, DAY1, AREAID
DAY 2, DAY 3, DAY 4, DAY5 DAY6.
DAY7 JOUR8, DAY9, DAY10, DAY 11,.
J13, DAY14 DAY12, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693745, 753740, '082013' 2167, 'X')
"FRLO < 1530 > ', ' < 1530 FRLO > ', '1530', 'FRLO', '1530',
'X', 'X', '1530', '1530', ' 1530',
"1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
(0, 0);
Insert in CALENDARS
(SCHEDULEID, EMPID, PERIODID, DAY1, AREAID
DAY 2, DAY 3, DAY 4, DAY5 DAY6.
DAY7 JOUR8, DAY9, DAY10, DAY 11,.
J13, DAY14 DAY12, NOPTIND1, NOPTIND2,
NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
NOPTIND13, NOPTIND14)
Values
(3693746, 753748, '082013' 2167, 'X')
"FRLO < 1530 > ', '1530', '1530', '1530', '1530',.
'X', 'X', ' FRLO < 1530 > ', '1530', 'FRLO ',.
"1530', '1530', 'X', 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
(0, 0);
COMMIT;
Insert into PAYPERIODS
(PERIODID, STARTPP)
Values
(TO_DATE '082013', (MARCH 24, 2013 00:00:00 "," MM/DD/YYYY HH24:MI:SS'));))
COMMIT;Hello
I think you want:
SELECT s.empid, pp.startpp, startdate, NULL starttime, NULL endtime, 8 hours, 0 minutes FROM schedules s JOIN payperiods pp ON pp.periodid = s.periodid WHERE UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO' UNION SELECT s.empid, pp.startpp + 1, startdate, NULL starttime, NULL endtime, 8 hours, 0 minutes FROM schedules s JOIN payperiods pp ON pp.periodid = s.periodid WHERE UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO' --ETC.
Kind regards
Peter
-
[need help] Function body of PL/SQL returning the SQL with BI publisher
Hello
I'm new to BI publisher, back then I used ocj4 for pdf printing, but then we got BI publisher. We want to have a better relationship, since we always used the standard one.
My pl/sql like this look
the question is how can I generate a pdf with this query using BI publisher report, what should I do?DECLARE q varchar2(4000); list_betreuer htmldb_application_global.vc_arr2; list_semester htmldb_application_global.vc_arr2; list_status htmldb_application_global.vc_arr2; BEGIN -- variable to store the list list_betreuer := HTMLDB_UTIL.STRING_TO_TABLE(:P61_BETREUER); list_semester := HTMLDB_UTIL.STRING_TO_TABLE(:P61_SEMESTER); list_status := HTMLDB_UTIL.STRING_TO_TABLE(:P61_STATUS); -- Query begins q:= 'select p1.name, p1.vorname , a1.tel, a2.tel, '; q:= q||'ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name '; q:= q||'from person p1, person p2, adresse a1, adresse a2, '; q:= q||'zuordnungp_a zpa1,zuordnungp_a zpa2, '; q:= q||'abschlussarbeit ab, semester s '; q:= q||'WHERE ab.SEMESTER = s.OBJECTID (+) '; q:= q||'AND ab.STUDENT = p1.OBJECTID (+) '; q:= q||'AND ab.BETREUER = p2.OBJECTID (+) '; q:= q||'and p1.objectid = zpa1.person (+) '; q:= q||'and zpa1.adresse = a1.objectid (+) '; q:= q||'and zpa1.art (+)= ''Privat'' '; q:= q||'and p1.objectid = zpa2.person (+) '; q:= q||'and zpa2.adresse = a2.objectid (+) '; q:= q||'and zpa2.art (+)= ''Geschäft'' '; -- Loop for betreuer list FOR i in 1..list_betreuer.count LOOP IF i = 1 THEN q:= q||'AND (ab.betreuer = '||list_betreuer(i); ELSE q:= q||' OR ab.betreuer = '||list_betreuer(i); END IF; END LOOP; if (list_betreuer.count>0)THEN q:= q||')'; END IF; -- Loop for semester list FOR i in 1..list_semester.count LOOP IF i = 1 THEN q:= q||'AND (ab.semester = '||list_semester(i); ELSE q:= q||'OR ab.semester = '||list_semester(i); END IF; END LOOP; if (list_semester.count>0)THEN q:= q||')'; END IF; -- Loop for status list FOR i in 1..list_status.count LOOP IF i = 1 THEN q:= q||'AND (ab.status = '''||list_status(i)||''''; ELSE q:= q||'OR ab.status = '''||list_status(i)||''''; END IF; END LOOP; if (list_status.count>0)THEN q:= q||')'; END IF; -- htp.p(q); return q; END;
Thanks in advance
DannyCheck this out to see if this helps you. This article talks about passing parameters to the BI publisher of Apex report.
http://tylermuth.WordPress.com/2008/03/31/call-bi-Publisher-Web-services-from-apex/
Thank you!
-
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
I need a query that returns the average amount of characters from text colum in MS SQL.
I need a query that returns the average amount of characters from text colum in MS SQL.
Could someone show me how?Sorting, I need of the
DATALENGTH
function
-
the friends hyii UA HUD need help how to make a backup of the files from his deleted with (shift + delete) memory card
Hello
It seems that you want to restore the files removed from the memory card.
I will definitely help you with this.
I would say you can search the Internet for data recovery software by using your favorite search engine.
Warning: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.
It will be useful. If you have any other questions, feel free to let us know. We will be happy to help you.
Thank you.
-
I need help to write a script that detects the first instance of a paragraph style and then change
I need help to write a script that detects the first instance of a paragraph style and then he goes to a different paragraph style. I don't necessarily need someone to write all this, by the biggest problem is to find how to find just the first instance of the paragraph style. Any help would be greatly appreciated, thank you!
Hello
then try this with your active doc:
....................
myDoc var = app.activeDocument;
mStyle var = myDoc.paragraphStyles.item ("PS_NameToFind"); change the name to paraStyle
var mStyle_1 = myDoc.paragraphStyles.item ("PS_NameToChange"); change the name to paraStyle
var mFrames = myDoc.pages.everyItem ().textFrames.everyItem () .getElements ();
app.findTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = mStyle;
for (var k = 0; k)< mframes.length;="">
{
currFound = mFrames [k] .findText ();
If (currFound.length > 0)
currFound [0] .paragraphs [0] .appliedParagraphStyle = mStyle_1;
}
app.findTextPreferences = null;
................
Rgds
-
Need help with PL/SQL query complex
I need help with a query that need access to data from 3 tables. That's what I did
I created 3 tables
CREATE TABLE post_table
(
post_id varchar (20),
datepost DATE,
KEY (post_id) elementary SCHOOL
) ;
CREATE TABLE topic
(
TOPIC_ID varchar (20),
name varchar (20),
PRIMARY KEY (topic_id)
);
CREATE TABLE blogpost_table
(
TOPIC_ID varchar (20),
post_id varchar (20),
PRIMARY KEY (topic_id, post_id);
FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
);
Now, I inserted a few values in these tables as
INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO VALUES subject ("t1", "baseball");
INSERT INTO category VALUES ('t2', 'football');
INSERT INTO blogpost_table VALUES ("t1", "p1");
INSERT INTO blogpost_table VALUES ('t1', 'p3');
INSERT INTO blogpost_table VALUES ("t1", "p4");
INSERT INTO blogpost_table VALUES ('t1', 'p5');
INSERT INTO blogpost_table VALUES ('t2', 'p2');
INSERT INTO blogpost_table VALUES ('t2', 'p6');
INSERT INTO blogpost_table VALUES ("t2", "p7");
I'm launching SQL queries on the table in this topic.
I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.
Can someone please help me to write this query?
Thank you
Published by: user11994430 on October 9, 2009 07:24Thanks for the test of the configuration!
SQL>SELECT t.NAME, COUNT(*) 2 FROM topic t, blogpost_table b, post_table p 3 WHERE b.topic_id = t.topic_id 4 AND p.post_id = b.post_id 5 AND p.datepost >= DATE '2009-07-01' 6 AND p.datepost < DATE '2009-08-01' 7 GROUP BY t.NAME 8 ORDER BY COUNT(*) desc; NAME COUNT(*) -------------------- ---------- baseball 2 soccer 2
HTH, Urs
-
Need help with writing a query
Hi all
Can someone help please write a query for the following scenario
Data in the table are in the format below
student_name Sub1 sub1_marks Sub2 sub2_marks SUB3 sub3_marks John Math 90 Science 80 lang 85 Need to write a query to get it as
student_name Object brands of John Math 90 John Science 80 John lang 85
Thank youI'm looking so unpivoting the mulitple columns option is there. how it will be used
I certainly learned something new today.
create table student_marks( student_name varchar2(20), sub1 varchar2(20), sub1_marks number, sub2 varchar2(20), sub2_marks number, sub3 varchar2(20), sub3_marks number ) ; insert into student_marks values( 'john', 'math', 90, 'science', 80, 'lang', 85 ) ; select student_name, sub subject, marks from student_marks unpivot include nulls ( (sub, marks) for subject in ( (sub1, sub1_marks), (sub2, sub2_marks), (sub3, sub3_marks) ) ) ; drop table student_marks purge ; table STUDENT_MARKS created. 1 rows inserted. STUDENT_NAME SUBJECT MARKS -------------------- -------------------- ---------- john math 90 john science 80 john lang 85 table STUDENT_MARKS dropped.
-
Need help to build the query to group the lines
Hello all, hope someone can help me with this. I am working in Oracle 11 g PL/SQL 11.2.0.2.0.
I have the following query, which does exactly what I need, but I have been invited to consolidate the results in a specific way and I can't do that. First of all the existing request:
I was asked to do, is to display a number of facility_type who have each of the combinations of the 'DEAL' 33 areas. Installation types are strings. So an expected result would look something like:SELECT facility_id ,facility_type ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT ,COUNT (CASE WHEN component_type = 'BREAKERUSS' THEN 1 END) AS BREAKERUSS ,COUNT (CASE WHEN component_type = 'CAPACIFORMER' THEN 1 END) AS CAPACIFORMER ,COUNT (CASE WHEN component_type = 'CAPACITOR' THEN 1 END) AS CAPACITOR ,COUNT (CASE WHEN component_type = 'CEFIBEROPTIC' THEN 1 END) AS CEFIBEROPTIC ,COUNT (CASE WHEN component_type = 'ELASTIDISCONN' THEN 1 END) AS ELASTIDISCONN ,COUNT (CASE WHEN component_type = 'NETWORKPROTECT' THEN 1 END) AS NETWORKPROTECT ,COUNT (CASE WHEN component_type = 'POLE' THEN 1 END) AS POLE ,COUNT (CASE WHEN component_type = 'REACTOR' THEN 1 END) AS REACTOR ,COUNT (CASE WHEN component_type = 'RECLOSER3PUPOIL' THEN 1 END) AS RECLOSER3PUPOIL ,COUNT (CASE WHEN component_type = 'RECLOSERTSUP' THEN 1 END) AS RECLOSERTSUP ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRL3A' THEN 1 END) AS RECLSR3PCNTRL3A ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRLNT' THEN 1 END) AS RECLSR3PCNTRLNT ,COUNT (CASE WHEN component_type = 'RECLSRTSCNTRL' THEN 1 END) AS RECLSRTSCNTRL ,COUNT (CASE WHEN component_type = 'RECTIFIERUSS' THEN 1 END) AS RECTIFIERUSS ,COUNT (CASE WHEN component_type = 'REGULATORJOINT' THEN 1 END) AS REGULATORJOINT ,COUNT (CASE WHEN component_type = 'REGULATOROH' THEN 1 END) AS REGULATOROH ,COUNT (CASE WHEN component_type = 'REGULATORUSS' THEN 1 END) AS REGULATORUSS ,COUNT (CASE WHEN component_type = 'RMS' THEN 1 END) AS RMS ,COUNT (CASE WHEN component_type = 'SPLICEPRIMARY' THEN 1 END) AS SPLICEPRIMARY ,COUNT (CASE WHEN component_type = 'STREETLIGHT' THEN 1 END) AS STREETLIGHT ,COUNT (CASE WHEN component_type = 'SWITCHSCADA' THEN 1 END) AS SWITCHSCADA ,COUNT (CASE WHEN component_type = 'TAPCHANGER' THEN 1 END) AS TAPCHANGER ,COUNT (CASE WHEN component_type = 'TRAFFICSIGNAL' THEN 1 END) AS TRAFFICSIGNAL ,COUNT (CASE WHEN component_type = 'TRANSF480' THEN 1 END) AS TRANSF480 ,COUNT (CASE WHEN component_type = 'TRANSFGROUND' THEN 1 END) AS TRANSFGROUND ,COUNT (CASE WHEN component_type = 'TRANSFISOLATION' THEN 1 END) AS TRANSFISOLATION ,COUNT (CASE WHEN component_type = 'TRANSFOH' THEN 1 END) AS TRANSFOH ,COUNT (CASE WHEN component_type = 'TRANSFUG' THEN 1 END) AS TRANSFUG ,COUNT (CASE WHEN component_type = 'TRANSFURD' THEN 1 END) AS TRANSFURD ,COUNT (CASE WHEN component_type = 'TRANSFUSS' THEN 1 END) AS TRANSFUSS FROM (SELECT fy.id AS facility_id ,fy.external_facility_id ,fy.flty_facility_type as facility_type ,cp.cpty_component_type as component_type FROM facilities fy LEFT OUTER JOIN components cp ON cp.facility_id= fy.id ORDER BY fy.id DESC) GROUP BY facility_id, facility_type
FACILITY_TYPE | ATTACH2NDPARTY | ATTACH3RDPARTY | BREAKERGT | ... TRANSFUSS | COUNTY
MANHOLE X X 10
MANHOLE X X 22
POLE X X 5
and so on. Because there are 33 BUSINESS areas and therefore 33! possible combinations, I was thinking about a sort of loop would achieve the desired result, but I'm stuck and could really use a shot in the arm. Any help will be appreciated and obtained points! Thanks in advance.select facility_type ,ATTACH2NDPARTY ,ATTACH3NDPARTY -- and so on , count(*) cnt from ( --your query SELECT facility_id ,facility_type ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT ... ) group by facility_type ,ATTACH2NDPARTY ,ATTACH3NDPARTY -- and so on like in projection
-
need help for a conditional query
guys this is just. as an extension of this post that Frank was helping me. IM reposting because my needs change slightly and im having a hell of a time trying to change the query.
Here are the previous post.
need help with query can find data back please help.
dataCREATE TABLE "FGL" ( "FGL_GRNT_CODE" VARCHAR2(60), "FGL_FUND_CODE" VARCHAR2(60), "FGL_ACCT_CODE" VARCHAR2(60), "FGL_ORGN_CODE" VARCHAR2(60), "FGL_PROG_CODE" VARCHAR2(60), "FGL_GRNT_YEAR" VARCHAR2(60), "FGL_PERIOD" VARCHAR2(60), "FGL_BUDGET" VARCHAR2(60) )
I need to find the year of greater subsidy for the granting by a period setting.Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');
Once I found the great year, I need to check the value of the period 14 this grant for the previous year and add it to the amount of the budget for this grant. However if there is an entry in the biggest year for period 00 so I need to ignore the period 14 of the previous year and the current calculation period + (current period - more great year 00)
hope that makes sense, so in other words, with the new data above. If I asking me a second period of the grant year 11. I'd end up with $800
because the greatest year is 11 it contains one point 0 with $ 400, so my total should be
amount of period $2,600
period $0 400 - period $2 600 = $200
600 + 200 = $800
If I have question period 1 grant 360055 I'd end up just with 800 grnt year 10.
I tried to edit this query you have provided me with no luck. I tried for several embarrassed day but I'm saying I can just do what im trying to do.
can you please help me.
Here's the query provided by frank kulash who graciously put it together for me.
MiguelWITH got_greatest_year AS ( SELECT fgl.* -- or whatever columns are needed , MAX ( CASE WHEN fgl_period = :given_period THEN fgl_grnt_year END ) OVER () AS greatest_year FROM fgl ) SELECT SUM (fgl_budget) AS total_budget -- or SELECT * FROM got_greatest_year WHERE ( fgl_grnt_year = greatest_year AND fgl_period = :given_period ) OR ( fgl_grnt_year = greatest_year - 1 AND fgl_period = 14 ) ;
Hi, Miguel.
You are waying that when larger year who has: given_period also a period = '00' (or '0', or whatever it is you want to use), then you want to double the budget of the given_period (subtract the '00' budget and do not count '14' year pevious)? If so, add another condition to the CASE statement that decides what you've summarized:
WITH got_greatest_year AS ( SELECT TO_NUMBER (fgl_grnt_year) AS grnt_year , fgl_period , TO_NUMBER (fgl_budget) AS budget , MAX ( CASE WHEN fgl_period = :given_period THEN TO_NUMBER (fgl_grnt_year) END ) OVER () AS greatest_year FROM fgl ) , got_cnt_00 AS ( SELECT grnt_year , fgl_period , budget , greatest_year , COUNT ( CASE WHEN grnt_year = greatest_year AND fgl_period = '00' THEN 1 END ) OVER () AS cnt_00 FROM got_greatest_year ) SELECT SUM ( CASE WHEN grnt_year = greatest_year -- New AND fgl_period = :given_period -- New AND cnt_00 > 0 THEN budget * 2 -- New WHEN grnt_year = greatest_year AND fgl_period = :given_period THEN budget WHEN grnt_year = greatest_year AND fgl_period = '00' THEN -budget WHEN grnt_year = greatest_year - 1 AND fgl_period = '14' AND cnt_00 = 0 THEN budget END ) AS total_budget FROM got_cnt_00 ;
You will notice it is the same as the previous query, I posted, with the exception of 3 lines marked 'new '.
-
Need help to form a query SQL/PLSQL
Hello
I'm not an expert in Oracle SQL. I need to have this query to improve the performance of my product. I have a table T that has a collar of column that is of type varchar. The neck is unique in the table (no two rows have the same value for the collar). Given a set S1 with 100 channels, the query should return me all channels in S1 who are not present in the neck.
SQL query or PLSQL would be perfect. The query can have strings (elements of S1) hardcoded into it.
Thanks in advance,
Madhuuser13290641 wrote:
They are separate strings. They will be most likely hard-coded.In this case to pass them on in the form of record set as shown below, so that you can use operator LESS to get your result.
with static_result_set as ( select 'aaa' col from dual UNION ALL select 'xxx' from dual UNION ALL select 'ccc' from dual UNION ALL select 'zzz' from dual ) select col from static_result_set minus select col from t
-
Need help to design...
Hello.
I'm looking at the design and add some interactive flash for our company Web site.
Since we do a lot of business planning and consultation, we found a very good idea, but unfortunately, none of us really know to create.
Basically from what I did the research, I'll need to integrate animated buttons in a flash animation. I am attaching a quick sketch of what the site will look like. The part that I need assistance is the section of the middle with boxes.
What I do is the following:
The 5 gray boxes must be buttons that have a link to their related pages. (easy)
When loading the page, I want the animation to draw the first box, create the line, draw the second box, draw the next line, etc. until all the boxes and lines are drawn.
This is a mapping of the process, and since we do a lot of these for our work, we thought it would be good for us to integrate it into our Web site.
In addition, it would be ideal that these boxes have links to various pages on the site as well.
So my question is this:
-What should I do to get this animation work
-Where is a good place to start looking into what is the creation of something like that
-Is still possible
Thank you in advance,
Konrad
Yes, it is possible. You can do animation using a process similar to that used in this tutorial http://www.tutvid.com/tutorials/flash/tutorials/growingVinesAnimation.php. Then just add areas affected on the boxes to make them clickable. I am happy to help you further if you don't get it after seeing this tutorial, let me know - [email protected].
There are probably a dozen different ways to do it, it's just an idea that should work.
I hope that helps!
pigeon7081
-
Help with the query to return the last possible value
Can someone please help me to 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
I will return the following:
A, B, 2
C, D, 4
In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
The table has no index, and it is responsible for a worksheet in that order.
Thank you very much!Hello
If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.
WITH got_rnum AS ( SELECT my_table.* , RANK () OVER (ORDER BY entry_dt DESC) AS rnum FROM my_table ) SELECT * -- or list all columns except rnum FROM got_rnum WHERE rnum <= x ;
It is very common to have a trigger to ensure that columns like entry_dt are met.
If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same. -
Help with the query to return the results of the group in the table?
Hello
Im a total noob, so please be nice...!
I'm looking around a table contains a column of WORD and a WORD_TYPE_ID column.
Words can have the same type_id.
What I'm trying to do is to write a query that will return the longest word for each word_type_id.
I tried for hours to get it and everything seems to get is two error messages or just the longest word in the whole WORD column.
Is the furthest I can get before things break down...
Select Word
table
where
Length (Word) =
(
Select
Max (length (Word))
table
)
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
Thank youHello
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 be a tie in some word_type_id (i.e. 2 or more words have exactly the same length, which is the longest in this group) the expression above will return the first one alphabetically. (This is what means here MIN.)
Published by: Frank Kulash, 11 August 2009 13:56
You almost had it.
As you have noticed, you get the longest line across the table. This is because your subquery was watching the entire table.
If you to correlate the subquery 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 );
Maybe you are looking for
-
Share photos unmodified?
In the Apple pictures, is there a way to share the unedited original photo? I have a picture in my pictures that I then add a shared folder. When I click on Get info on them or check them on the original files, or export system, they seem to be of di
-
HP ACT026TX: INSTALLATION OF THE AMD DRIVER
I repeatedly install and uninstall the drivers of graphics from amd (R 5 330) but its not working not properly. It's very critical problems with laptops this configuration, I also install Windows 7 32 bit and after I installed window 7 64 bitbut prob
-
Impossible to play videos from YouTube!
From today, I can no longer play YouTube videos in my Safari browser. When I open a page on YouTube, I get this error message: "your browser does not currently recognize the video formats available.» I don't have Flash installed and I use the exten
-
Fatal error during installation of HP Deskjet F2180 Solution Center
Hello world! During the installation of the HP Deskjet F2180 Solution Center, it says "fatal error" - couldn t write the key to '\SOFTWARE' more 'MSI '. GPBaseService2"error. I tried several times to completely uninstall all this software and remove
-
I have a new windows 7 and this update KB954430 keeps coming to install. I checked the history and it has been installed more than 20 times. What are Microsoft. How do I step there. In my old XP pc you can isolate/block an item in the Update window.