Displaying Missing Rows in a Group By Select Statement
I have a query that looks like the following
select coll_time,sum(coll_size) from coll_table
where coll_time between '2007-11-15' and '2007-11-20'
group by coll_time;
This returns
coll_time sum(coll_size)
2007-11-15 123456
2007-11-16 234567
2007-11-17 345678
2007-11-19 456789
As you can see, there is no data for the 18th.
Can someone please explain how I can have the query output a row for the 18th. The sum can be 0 or null.
Thanks.
I may be missing something because when I execute the query against my data I'm still missing the missing dates. I'd like to see all the data (even 0) from Nov 10 to December 20. However when I perform the query I get information only for the dates for which there is data. Note that I am missing line items for Nov 18 as well as Dec 19/20 among others.
Thanks for your help.
VARIABLE start_date varchar2(100);
VARIABLE max_date varchar2(100);
EXEC :start_date := '2007-11-10';
EXEC :max_date := '2007-12-20';
WITH all_dates AS (
SELECT
to_date(:start_date,'yyyy-mm-dd') + level - 1 AS the_date
FROM
dual
CONNECT BY
level <= to_date(:max_date,'yyyy-mm-dd') - to_date(:start_date,'yyyy-mm-dd') + 1
SELECT
to_char(rcm.time, 'yyyy-mm-dd') coll_date,
SUM(rcm.datasize) dsize
FROM
all_dates ad,METRICS rcm
WHERE
rcm.ta = 'TEST_03'
AND
trunc(ad.the_date) = trunc(rcm.time (+))
GROUP BY
to_char(rcm.time, 'yyyy-mm-dd')
ORDER BY 1;
COLL_DATE DSIZE
2007-11-14 44902934
2007-11-15 44902934
2007-11-16 44902934
2007-11-17 22451467
2007-11-19 67354401
2007-11-20 44902934
2007-11-21 44902934
2007-11-22 44902934
2007-11-23 44902934
2007-11-24 44902934
2007-11-25 44902934
2007-11-26 44902934
2007-11-27 44902934
2007-11-28 44902934
2007-11-29 44902934
2007-11-30 89805868
2007-12-01 44902934
2007-12-03 22451467
2007-12-04 22451467
2007-12-05 67354401
2007-12-06 44902934
2007-12-07 44902934
2007-12-08 22451467
2007-12-09 22451467
2007-12-10 22451467
2007-12-11 44902934
2007-12-12 44902934
2007-12-13 44902934
2007-12-14 44902934
2007-12-15 44902934
2007-12-16 44902934
2007-12-17 44902934
2007-12-18 44902934
Similar Messages
-
How to display number of rows as columns in a select statement? This is on
How to display number of rows as columns in a select statement? This is on 10g R2.
Thanks,
RFor the current (ie. row 1 of 100)
row_number over (order by -pick_a_column_set) as rnfor the total number of columns returned in your query
count(*) over() as total_count -
Group By Select Statement aggregate function error.
I am using Dreamweaver MX4 and have an ASP web page. I can easily do this in Access 2007 a simple "group by" sum totals statement.
Why can I not get this to work on a web page? Are the "#" signs messing this up in the Code2 Select Statement?
How can I get Code2 to work correctly? Code1 works fine. A user enters the customer and a date range on a form and submits request. I get error message in Dreamweaver. You tried to execute a query where the specified expression field3 is not part of an aggregate function
Code1. This works fine SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #1/2/09# AND Field6 <= #1/30/09# GROUP BY Field3, Field10
Code2. I get error message SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #Date1# AND Field6 <= #Date2# GROUP BY Field3, Field10I am using Dreamweaver MX4 and have an ASP web page. I can easily do this in Access 2007 a simple "group by" sum totals statement.
Why can I not get this to work on a web page? Are the "#" signs messing this up in the Code2 Select Statement?
How can I get Code2 to work correctly? Code1 works fine. A user enters the customer and a date range on a form and submits request. I get error message in Dreamweaver. You tried to execute a query where the specified expression field3 is not part of an aggregate function
Code1. This works fine SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #1/2/09# AND Field6 <= #1/30/09# GROUP BY Field3, Field10
Code2. I get error message SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #Date1# AND Field6 <= #Date2# GROUP BY Field3, Field10 -
How Can I Get Group By Select Statement To WorK?
How can I get Code2 to work correctly? Code1 works fine. A user enters the customer and a date range on a form and submits request. I get error message in Dreamweaver. You tried to execute a query where the specified expression field3 is not part of an aggragate function I set the Form variables to: Name Default Value RunTime Value Search_Criteria 1 Request.Form("Search") Date1 1 Request.Form("Date1") Date2 1 Request.Form("Date2") Code1. This works fine SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #1/2/09# AND Field6 <= #1/30/09# GROUP BY Field3, Field10 Code2. I get error message SELECT Field3, Field10, SUM(Field16) as SumofField16 FROM CustomerHistory_CP WHERE Field3 LIKE '%Search_Criteria%' AND Field6 >= #Date1# AND Field6 <= #Date2# GROUP BY Field3, Field10
That requires you to enter the configuration correctly. You can find out the configuration for your email from your ISPs website in most cases. Or if you're using Gmail, Yahoo, or Hotmail you need only Google something like:
"Gmail configuration for Apple Mail" or "Hotmail configuration for Apple Mail" (without the quotes).
That should get you started..
Jeff -
MySQL Select Statement Help Required
I am trying to generate a report in VS 2008 (C#) using a mysql select statement but cannot get it right.
I have groups that meet on a weekly basis on different days. I want to generate a report that shows me all the members that have not attended their group where they have missed 3 meetings in a row.
Below is the select statement I have tried but it does not give me the results I am looking for. I have tried to look at all the meetings in a 4 week period but would prefer to look at the last 3 meetings that are recorded. Some groups might not record a meeting every week. So I want to look at the last 3 recorded meetings and count each members attendance and only report on the members with more than 3 meetings missed.
SELECT COUNT(`groupattendance`.`Attended`) AS Attendance, `smallgroupform`.`MeetingDate`, `userinfo`.`FirstName`, `userinfo`.`Surname`, `smallgroup`.`GroupName`, `groupattendance`.`Attended`, `groupattendance`.`UserID`, `groupattendance`.`GroupID`
FROM ((`anatomy`.`groupattendance` `groupattendance`
INNER JOIN `anatomy`.`smallgroupform` `smallgroupform` ON `groupattendance`.`FormID` = `smallgroupform`.`FormID`)
INNER JOIN `anatomy`.`userinfo` `userinfo` ON `groupattendance`.`UserID` = `userinfo`.`UserID`)
INNER JOIN `anatomy`.`smallgroup` `smallgroup` ON `groupattendance`.`GroupID` = `smallgroup`.`GroupID`
WHERE (`smallgroupform`.`MeetingDate` >= DATE_SUB(CURDATE(),INTERVAL 4 WEEK) AND `smallgroupform`.`MeetingDate` <= CURDATE()) AND `groupattendance`.`Attended` = 'False'
GROUP BY `userinfo`.`UserID`
HAVING Attendance >= 3
Thanks,
Garth.Hi Garth,
Seems no one can help you directly. Try googling your SQL request. Someone may be able to help you. At this point its not really a Cr problem.
One option is to get all the data and add filtering using the record selection formula.
Thank you
Don -
Trouble on launch a select statement twice
Hello everyone,
this is my problem: when i launch this query the first time, it returns 2 records, if i launch it the second time it returns no records.
I tried to remove SUM(NVL) and the group by and the query functions normally.
select SUM (NVL (a.burdened_cost, 0)) AS amount ,c.track_as_labor_flag,a.start_date, a.end_date
FROM nome_vista a, nome_tabella b,nome_tabella c
WHERE a.project_id = ...
AND a.task_id = ...
AND a.budget_version_id = b.budget_version_id
AND NVL (b.current_flag, 'N') = 'Y'
AND b.budget_status_code = ...
AND b.budget_type_code = ...
AND c.track_as_labor_flag = ... --filtro costi interni
AND c.resource_id = a.resource_id
Group By c.track_as_labor_flag,a.start_date, a.end_dateThank You
Edited by: BluShadow on 27-Jul-2011 13:52
added {noformat}{noformat} tags for readability. Please see {message:id=9360002} to learn to do this yourself.SQL> set autotrace on;
SQL> SQL> select SUM (NVL (a.burdened_cost, 0)) AS amount
,c.track_as_labor_flag
,a.start_date
,a.end_date
2 FROM pa_budget_lines_v a,
3 pa_budget_versions b,
4 pa_resource_list_members c
5 WHERE a.project_id = 1879
6 AND a.task_id = 211004
7 AND a.budget_version_id = b.budget_version_id
8 AND NVL (b.current_flag, 'N') = 'Y'
9 AND b.budget_status_code = 'B'
10 AND b.budget_type_code = 'AC'
11 AND c.track_as_labor_flag = 'Y' --filtro costi interni
12 AND c.resource_id = a.resource_id
13 Group By c.track_as_labor_flag,a.start_date, a.end_date;
AMOUNT T START_DA END_DATE
2919,2 Y 10-07-01 10-12-31
945,36 Y 10-01-01 11-01-31
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 1 | 161 | 19 (11)|
| 1 | HASH GROUP BY | | 1 | 161 | 19 (11)|
|* 2 | HASH JOIN | | 1 | 161 | 18 (6)|
| 3 | NESTED LOOPS OUTER | | 1 | 154 | 11 (0)|
| 4 | NESTED LOOPS | | 1 | 118 | 10 (0)|
| 5 | NESTED LOOPS | | 1 | 91 | 8 (0)|
| 6 | NESTED LOOPS | | 1 | 79 | 7 (0)|
| 7 | NESTED LOOPS OUTER | | 1 | 67 | 6 (0)|
|* 8 | TABLE ACCESS BY INDEX ROWID| PA_RESOURCE_ASSIGNMENTS | 1 | 31 | 5 (0)|
|* 9 | INDEX RANGE SCAN | PA_RESOURCE_ASSIGNMENTS_N2 | 6 | | 1 (0)|
|* 10 | INDEX UNIQUE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 36 | 1 (0)|
|* 11 | TABLE ACCESS BY INDEX ROWID | PA_BUDGET_VERSIONS | 1 | 12 | 1 (0)|
|* 12 | INDEX UNIQUE SCAN | PA_BUDGET_VERSIONS_U1 | 1 | | 0 (0)|
|* 13 | TABLE ACCESS BY INDEX ROWID | PA_RESOURCE_LIST_MEMBERS | 1 | 12 | 1 (0)|
|* 14 | INDEX UNIQUE SCAN | PA_RESOURCE_LIST_MEMBERS_U1 | 1 | | 0 (0)|
| 15 | TABLE ACCESS BY INDEX ROWID | PA_BUDGET_LINES | 1 | 27 | 2 (0)|
|* 16 | INDEX RANGE SCAN | PA_BUDGET_LINES_N2 | 1 | | 1 (0)|
|* 17 | INDEX UNIQUE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 36 | 1 (0)|
|* 18 | TABLE ACCESS FULL | PA_RESOURCE_LIST_MEMBERS | 121 | 847 | 6 (0)|
Predicate Information (identified by operation id):
2 - access("C"."RESOURCE_ID"="M"."RESOURCE_ID")
8 - filter("A"."PROJECT_ID"=1879)
9 - access("A"."TASK_ID"=211004)
10 - access("LOOKUP_TYPE"(+)='UNIT' AND "VIEW_APPLICATION_ID"(+)=275 AND
"A"."UNIT_OF_MEASURE"="LOOKUP_CODE"(+) AND "SECURITY_GROUP_ID"(+)=
0 AND
"LANGUAGE"(+)=USERENV('LANG'))
11 - filter("B"."BUDGET_STATUS_CODE"='B' AND "B"."CURRENT_FLAG"='Y' AND
"B"."BUDGET_TYPE_CODE"='AC')
12 - access("A"."BUDGET_VERSION_ID"="B"."BUDGET_VERSION_ID")
13 - filter(NVL("M"."MIGRATION_CODE",'-99')<>'N')
14 - access("A"."RESOURCE_LIST_MEMBER_ID"="M"."RESOURCE_LIST_MEMBER_ID")
16 - access("I"."RESOURCE_ASSIGNMENT_ID"="A"."RESOURCE_ASSIGNMENT_ID")
17 - access("LOOKUP_TYPE"(+)='BUDGET CHANGE REASON' AND "VIEW_APPLICATION_ID"(
+)=275 AND
"I"."CHANGE_REASON_CODE"="LOOKUP_CODE"(+) AND "SECURITY_GROUP_ID"(
+)=0 AND
"LANGUAGE"(+)=USERENV('LANG'))
18 - filter("C"."TRACK_AS_LABOR_FLAG"='Y')
Note
--- 'PLAN_TABLE' is old version
Statistics
22 recursive calls
0 db block gets
145 consistent gets
21 physical reads
0 redo size
574 bytes sent via SQL*Net to client
337 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
SQL> select SUM (NVL (a.burdened_cost, 0)) AS amount
,c.track_as_labor_flag
,a.start_date
,a.end_date
2 FROM pa_budget_lines_v a,
3 pa_budget_versions b,
4 pa_resource_list_members c
5 WHERE a.project_id = 1879
6 AND a.task_id = 211004
7 AND a.budget_version_id = b.budget_version_id
8 AND NVL (b.current_flag, 'N') = 'Y'
9 AND b.budget_status_code = 'B'
10 AND b.budget_type_code = 'AC'
11 AND c.track_as_labor_flag = 'Y' --filtro costi interni
12 AND c.resource_id = a.resource_id
13 Group By c.track_as_labor_flag,a.start_date, a.end_date;
no rows selected
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 1 | 161 | 19 (11)|
| 1 | HASH GROUP BY | | 1 | 161 | 19 (11)|
|* 2 | HASH JOIN | | 1 | 161 | 18 (6)|
| 3 | NESTED LOOPS OUTER | | 1 | 154 | 11 (0)|
| 4 | NESTED LOOPS | | 1 | 118 | 10 (0)|
| 5 | NESTED LOOPS | | 1 | 91 | 8 (0)|
| 6 | NESTED LOOPS | | 1 | 79 | 7 (0)|
| 7 | NESTED LOOPS OUTER | | 1 | 67 | 6 (0)|
|* 8 | TABLE ACCESS BY INDEX ROWID| PA_RESOURCE_ASSIGNMENTS | 1 | 31 | 5 (0)|
|* 9 | INDEX RANGE SCAN | PA_RESOURCE_ASSIGNMENTS_N2 | 6 | | 1 (0)|
|* 10 | INDEX UNIQUE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 36 | 1 (0)|
|* 11 | TABLE ACCESS BY INDEX ROWID | PA_BUDGET_VERSIONS | 1 | 12 | 1 (0)|
|* 12 | INDEX UNIQUE SCAN | PA_BUDGET_VERSIONS_U1 | 1 | | 0 (0)|
|* 13 | TABLE ACCESS BY INDEX ROWID | PA_RESOURCE_LIST_MEMBERS | 1 | 12 | 1 (0)|
|* 14 | INDEX UNIQUE SCAN | PA_RESOURCE_LIST_MEMBERS_U1 | 1 | | 0 (0)|
| 15 | TABLE ACCESS BY INDEX ROWID | PA_BUDGET_LINES | 1 | 27 | 2 (0)|
|* 16 | INDEX RANGE SCAN | PA_BUDGET_LINES_N2 | 1 | | 1 (0)|
|* 17 | INDEX UNIQUE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 36 | 1 (0)|
|* 18 | TABLE ACCESS FULL | PA_RESOURCE_LIST_MEMBERS | 121 | 847 | 6 (0)|
Predicate Information (identified by operation id):
2 - access("C"."RESOURCE_ID"="M"."RESOURCE_ID")
8 - filter("A"."PROJECT_ID"=1879)
9 - access("A"."TASK_ID"=211004)
10 - access("LOOKUP_TYPE"(+)='UNIT' AND "VIEW_APPLICATION_ID"(+)=275 AND
"A"."UNIT_OF_MEASURE"="LOOKUP_CODE"(+) AND "SECURITY_GROUP_ID"(+)=
0 AND
"LANGUAGE"(+)=USERENV('LANG'))
11 - filter("B"."BUDGET_STATUS_CODE"='B' AND "B"."CURRENT_FLAG"='Y' AND
"B"."BUDGET_TYPE_CODE"='AC')
12 - access("A"."BUDGET_VERSION_ID"="B"."BUDGET_VERSION_ID")
13 - filter(NVL("M"."MIGRATION_CODE",'-99')<>'N')
14 - access("A"."RESOURCE_LIST_MEMBER_ID"="M"."RESOURCE_LIST_MEMBER_ID")
16 - access("I"."RESOURCE_ASSIGNMENT_ID"="A"."RESOURCE_ASSIGNMENT_ID")
17 - access("LOOKUP_TYPE"(+)='BUDGET CHANGE REASON' AND "VIEW_APPLICATION_ID"(
+)=275 AND
"I"."CHANGE_REASON_CODE"="LOOKUP_CODE"(+) AND "SECURITY_GROUP_ID"(
+)=0 AND
"LANGUAGE"(+)=USERENV('LANG'))
18 - filter("C"."TRACK_AS_LABOR_FLAG"='Y')
Note
- 'PLAN_TABLE' is old version
Statistics
22 recursive calls
2 db block gets
9 consistent gets
0 physical reads
0 redo size
416 bytes sent via SQL*Net to client
326 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processedEdited by: -deb- on 28-lug-2011 2.44
Edited by: BluShadow on 28-Jul-2011 10:57
added {noformat}{noformat} tags again! This is the last time I'll do it for you. -
How can i retrieve the output of procedure using a select statement ?
Hi every one.
this mite be dumm ?
how can i use the output of the a procedure containing multiple rows of data in a select statement ?This is not a SQL Developer question. You should ask it in the SQL and PL/SQL forum.
The short answer is you can't. Sounds is if you are trying to use MSSQL techniques in oracle. Learn oracle techniques -
Group Above Report problem...not able to display absent rows in date range
In my report query, I have numerous select statements that I must union together and group by a date. The ultimate goal is to get a count for all records in coordination with that date. Then in the report, I group all the data with the same date to ultimately put all counts on a page that coordinate with a single date.
Thing is...if there are no records associated with that date, the 'group by' clause makes the return data set not include those lines of output. I need these lines of output! Any suggestions??
Below is an example...
Select 'Program1', 'SubProgram1', 'Label 1', to_char(receipt_date, 'MM/DD/RRRR'), count(*)
from submissions
where receipt_date between '01-JUN-05' and '10-JUN-05'
and substr(submission_index,8,1) = '3'
and substr(submission_index,9,1) = '1'
group by substr(submission_index,8,1), substr(submission_index,9,1), to_char(receipt_date, 'MM/DD/RRRR')
union
Select 'Program2', 'SubProgram2', 'Label 2',
to_char(receipt_date, 'MM/DD/RRRR'), count(*)
from submissions
where receipt_date between '01-JUN-05' and '10-JUN-05'
and substr(submission_index,8,1) = '4' group by substr(submission_index,8,1), to_char(receipt_date, 'MM/DD/RRRR')
OUTPUT:
Program1 SubProgram1 Label 1 06/01/2005 4
Program1 SubProgram1 Label 1 06/02/2005 2
Program1 SubProgram1 Label 1 06/03/2005 6
Program1 SubProgram1 Label 1 06/04/2005 23
Program1 SubProgram1 Label 1 06/06/2005 71
Program1 SubProgram1 Label 1 06/07/2005 245
Program1 SubProgram1 Label 1 06/08/2005 76
Program1 SubProgram1 Label 1 06/10/2005 45
Program2 SubProgram2 Label 2 06/01/2005 66
Program2 SubProgram2 Label 2 06/02/2005 345
Program2 SubProgram2 Label 2 06/03/2005 89
Program2 SubProgram2 Label 2 06/04/2005 12
Program2 SubProgram2 Label 2 06/05/2005 3
Program2 SubProgram2 Label 2 06/06/2005 27
Program2 SubProgram2 Label 2 06/09/2005 98
Program2 SubProgram2 Label 2 06/10/2005 456
I need the missing lines to show up for Program 1 on 6/05 and 6/09
and Program 2 on 6/07 and 6/08create table your_table (
program varchar2(20),
subprogram varchar2(20),
label varchar2(20),
day date,
num number
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('01-JUN-05'), 4);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('02-JUN-05'), 2);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('03-JUN-05'), 6);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('04-JUN-05'), 23);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('06-JUN-05'), 71);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('07-JUN-05'), 245);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('08-JUN-05'), 76);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('10-JUN-05'), 45);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('01-JUN-05'), 66);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('02-JUN-05'), 345);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('03-JUN-05'), 89);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('04-JUN-05'), 12);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('05-JUN-05'), 3);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('06-JUN-05'), 27);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('09-JUN-05'), 98);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('10-JUN-05'), 456);
SELECT yt.program
, yt.subprogram
, yt.label
, nvl(yt.num,0) NUM
, days.date_value
FROM ( select (to_date('11-JUN-05','DD-MON-YY') - day) date_value
from ( select rownum day
from dual
connect by rownum < 11
) days
, your_table yt
where yt.day(+) = days.date_value
order by yt.program, days.date_value
PROGRAM SUBPROGRAM LABEL NUM DATE_VALUE
Program1 SubProgram1 Label 1 4 6/1/2005
Program1 SubProgram1 Label 1 2 6/2/2005
Program1 SubProgram1 Label 1 6 6/3/2005
Program1 SubProgram1 Label 1 23 6/4/2005
Program1 SubProgram1 Label 1 71 6/6/2005
Program1 SubProgram1 Label 1 245 6/7/2005
Program1 SubProgram1 Label 1 76 6/8/2005
Program1 SubProgram1 Label 1 45 6/10/2005
Program2 SubProgram2 Label 2 66 6/1/2005
Program2 SubProgram2 Label 2 345 6/2/2005
Program2 SubProgram2 Label 2 89 6/3/2005
Program2 SubProgram2 Label 2 12 6/4/2005
Program2 SubProgram2 Label 2 3 6/5/2005
Program2 SubProgram2 Label 2 27 6/6/2005
Program2 SubProgram2 Label 2 98 6/9/2005
Program2 SubProgram2 Label 2 456 6/10/2005The four null rows will not show up because the date is used at least once between program 1 or program 2. Will there only ever be two programs to chose from? Any one else got any ideas around this? -
Display last two rows for every group
Hi,
I want to display only last 2 rows for every group.
My table look like
ACN DATE COST APPL
A6ERA 14-JUN 150 B777
A6ERA 14-JUN 180 B787
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 13-JUN 166 A777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
In the above table, I want to display only the last two rows group by ACN
Like the below table
ACN DATE COST APPL
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
Please replyNihar
To get the first two rows from each group, you could do this:
Use the ROW_NUMBER() analytic function (see http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions137.htm#i86310)
Now, your question isn't clear what you mean by "last" two rows. Last in what order? Whatever it is, you can use the ORDER BY part of the ROW_NUMBER() function to specify the ordering, and reverse it using DESC - for example:
select acn, adate, cost, appl from (
select acn, adate, cost, appl,
row_number() over (partition by acn order by adate desc) as rn
from acntab
where rn <= 2
order by acn, rnHTH
Regards Nigel -
How display number of row in select statement
How can I display number of row in select statement?
Table
data1 data2
xxx ccd
wss qwe
qws uij
I need get from SELECT statement:
1 xxx ccd
2 wss qwe
3 qws uijuser13734495 wrote:
Thank you from answer.
Statement
select rownum rn, data1, data2 from table
is good.
And what have I do went I use
select rownum rn, data1, data2 from table order by data1
and I get
3 qws uij
2 wss qwe
1 xxx ccd
I need
1 qws uij
2 wss qwe
3 xxx ccdhence the importance of describing the complete problem.
select
rownum,
data1,
data2
from(
select
data1,
data2
from
table
order by
data1) -
Hi Guys,
I tried Group By from Select Top 1 Records, As below the script wasn't work.
Please help.
SELECT TOP 1 NR.SHGId, NR.Amount
FROM NEW_DCB_REPORT NR
WHERE NR.SHGId = ND.SHGId
AND NR.ShgMemberId = ND.ShgMemberId
AND NR.LoanNumber = ND.LoanNumber
GROUP BY NR.SHGId,NR.Amount
ORDER BY NR.LedgerNumber DESC
SHGId
SHGMemberId
LoanNumber
Amount
Select Top 1 Row
1028
147852
1
1000
Select Top 1 Row
1028
147853
1
2000
Select Top 1 Row
1028
147854
1
1000
Select Top 1 Row
1028
147855
1
1000
5000
I expected the results are:
SHGId
Amount
1028
5000Yes I did it.
Select SHGId,
SUM(Amount)
amt FROM
SELECT NR.SHGId,
NR.Amount,
, Row_number()
Over(partition
by NR.SHGId,
NR.ShgMemberId , NR.LoanNumber
Order
by NR.LedgerNumber
DESC
) rn
FROM NEW_DCB_REPORT NR
JOIN
NEW_DCB_REPORT ND
ON
NR.SHGId
=
ND.SHGId
AND NR.ShgMemberId
= ND.ShgMemberId
AND NR.LoanNumber
= ND.LoanNumber
) t
Where rn=1
GROUP
BY SHGId
I just changed above the script Partition by add one more column and
[yourNDTable]
Should come NEW_DCB_REPORT table.
However, It shows below the error ,. Please help.
Invalid object name 'NEW_DCB_REPORT'. -
BPC 7M SP4 EVDRE missing rows - Error is "1004-Selection is too large.}
Hello,
On a customer who installed BPC 7 Ms SP4 I have on client Exception log the error:
===================[System Error Tracing]=====================
[System Name] : BPC_ExcelAddin
[Job Name] : clsExpand::applyDataRangeFormula
[DateTime] : 2009-07-17 09:44:13
[Exception]
Detail<sg : {1004-Selection is too large}
===================[System Error Tracing End ]=====================
When I see this error there is an EVDRE input schedule expanding which have some of the rows missing rows descriptions.
This means there is a gap of missing row header formulas stating from second row to somewhere in the middle of the report.
If I reduce the number of the resulting rows for the same EVDRE input schedule results are ok.
Do you know some setting to fix this?
I tried increasing the Maximum Expansion Limit for rows and columns in Workbook Options without success.
Thank you.Hi all,
I have the same problem with 7.0MS SP07. With 59 expanded members it works. With 60 expanded members it fails.
Mihaela, could you explain us what is the purpose of the parameters you talk about?
thanks,
Romuald -
How To Restrict Number Of Rows For Multiple Group In Report Output
Hi ,
I have a requirement to restrict number of rows in report output.I have three different group , if i use same no of rows to restrict then output is as expected but if i want Deduction group should have 7 rows , earning should have 5 rows and Tax group have 3 rows in report output then XML tag is not working.
Below is the XML tag i am using -
First i have declare the variable to restrict the rows -
<xsl:variable name="lpp" select="number(7)"/>
<xsl:variable name="lpp1" select="number(5)"/>
<xsl:variable name="lpp2" select="number(3)"/>
For Each -
<?for-each:PAYSLIP?>
<xsl:variable xdofo:ctx="incontext" name="DedLines" select=".//AC_DEDUCTIONS"/>
<xsl:variable xdofo:ctx="incontext" name="EarLines" select=".//AC_EARNINGS[ELEMENT_CLASSIFICATION!='Taxable Benefits']"/>
<xsl:variable xdofo:ctx="incontext" name="EarTaxLines" select=".//AC_EARNINGS[ELEMENT_CLASSIFICATION='Taxable Benefits']>
<?for-each:$DedLines?><?if:(position()-1) mod $lpp=0?> <xsl:variable name="start" xdofo:ctx="incontext" select="position()"/>
<?if:(position()-1) mod $lpp1=0?><xsl:variable name="start1" xdofo:ctx="incontext" select="position()"/
<?if:(position()-1) mod $lpp2=0?><xsl:variable name="start2" xdofo:ctx="incontext" select="position()"/>
Report output is tabular form (one page has two column - Earning and Deduction ) . Tax group comes below earning group.
Deduction Group -
<?for-each-group:$DedLines;./REPORTING_NAME?><?if:position()>=$start and position()<$start+$lpp?>
<?REPORTING_NAME?>
<?end if?><?end for-each-group?>
Earning Group -
<?for-each-group:$EarLines;./REPORTING_NAME?><?if:position()>=$start1 and position()<$start1+$lpp1?>
<?REPORTING_NAME?>
<?end if?><?end for-each-group?>
Tax Group -
<?for-each-group:$EarTaxLines;./REPORTING_NAME?><?if:position()>=$start2 and position()<$start2+$lpp2?>
<?REPORTING_NAME?>
<?end if?><?end for-each-group?>
Please let me know in case additional detail is require.
Thanks in Advance.
Thanks,
Harsh
Edited by: Harsh.rkg on Jan 14, 2013 9:43 PMvariable lpp2 is declare to restrict EarTaxLines -
<xsl:variable name="lpp2" select="number(2)"/>
This will help to restrict the no of rows on one page , if we have more then two tax benefits line then layout will roll over to continuation page.
As part of report output my expectation is if i restrict Earning , Deduction and Tax benefits to same no of line for example - variable lpp ,lpp1 and lpp2 have same value "number(2)" , we can see the layout is continue on next page (restrict every group can have max two lines) .This is the reason we have 4 header grid , deduction and Tax Benefit lines are rolled over to continuation page .But if we restrict different value for each variable then continuation page layout is missing .
When we tried for <xsl:variable name="lpp2" select="number(3)"/> value continuation page layout is not getting generate for both employee number . -
How can I display the rows into columns.
How can I display the rows into columns. I mean
Create table STYLE_M
(Master varchar2(10), child varchar2(10));
Insert itno style_m
('MASTER1','CHILD1');
Insert itno style_m
('MASTER2','CHILD1');
Insert itno style_m
('MASTER2','CHILD2');
Insert itno style_m
('MASTER3','CHILD1');
Insert itno style_m
('MASTER3','CHILD2');
Insert itno style_m
('MASTER3','CHILD3');
Note : The Master may have any number of childs.
I want to display like this..
Master child1, child2, child3, .......(dynamic)
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3
Sorry for disturbing you. Please hlp me out if you have any slution.
Thanks alot.
Ram DontineniHere's a straight SQL "non-dynamic" approach.
This would be used if you knew the amount of children.
SELECT
master,
MAX(DECODE(r, 1, child, NULL)) || ' ' || MAX(DECODE(r, 2, child, NULL)) || ' ' || MAX(DECODE(r, 3, child, NULL)) children
FROM
SELECT
master,
child,
ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r
FROM
style_m
GROUP BY
master
MASTER CHILDREN
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3 Since you said that the number of children can vary, I incorporated the same logic into a dynamic query.
SET AUTOPRINT ON
VAR x REFCURSOR
DECLARE
v_sql VARCHAR2(1000) := 'SELECT master, ';
v_group_by VARCHAR2(200) := 'FROM (SELECT master, child, ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r FROM style_m) GROUP BY master';
v_count PLS_INTEGER;
BEGIN
SELECT
MAX(COUNT(*))
INTO v_count
FROM
style_m
GROUP BY
master;
FOR i IN 1..v_count
LOOP
v_sql := v_sql || 'MAX(DECODE(r, ' || i || ', child, NULL))' || ' || '' '' || ';
END LOOP;
v_sql := RTRIM(v_sql, ' || '' '' ||') ||' children ' || v_group_by;
OPEN :x FOR v_sql;
END;
PL/SQL procedure successfully completed.
MASTER CHILDREN
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3I'll point your other thread to this one. -
Post Author: sunny07
CA Forum: General
I would like to display missing test results in the below format.
Group 1: product group
Test ID 1 Test ID 2 Test ID 3 Test ID 4
Unit Number *
Group 2: product group will have different tests than group 1.
Test ID 5 Test ID 6
Unit Number *
(* test is missing)
Any suggestions how I should set this up in Crystal Reports?Post Author: sunny07
CA Forum: General
User will be prompted for a donation type which they will select from a drop down menu. They will only be able to select one donation type when the report is run. There are only 4 donation types that the users can choose from. There are different test Ids for each donation type. The test IDs for each donation type are not defined in the database. Any suggests how I define the test IDs for each donation type IN CR 11.5? Any suggestion how I display the test IDs as displayed below? Connecting to an Oracle database. 24BA, FINB, HBC, HCV, ABRH, ABS are examples of test IDs.
Example running report for the donation type Bacterial Culture:
Unit Number Batch ID 24BA FINB HBC HCV
W03305100919 20070321HI * *
Example running the report for the donation type ABO Screen:
Unit Number Batch ID ABRH ABS
W035304100926 20070320HI *
W035304100932 20070320HI
W035304100932 will appear on the report because it has ABO Screen donation type. This unit does not have any missing test results.
*The test ID does not exist for this unit number.
Thanks!
Maybe you are looking for
-
Please help. My DS created a document under his login on my PowerBook and now, I cannot seem to access it. He doesn't have an email account of his own, I can't seem to save it as a public document in a drop box like I can from my own login and we do
-
How to stop a cluster constant typedef from resizing when the typedef is changed?
Using LabVIEW 7.1... I've been using cluster typedefs to make make constants on the block diagram. I usually resize them so they are nearly the size of a few characters. When the typedef is updated the constant expands to full size. Usually I can
-
Non-static method close() cannot be referenced from a static context
Friends, I am having a little help with some static and not static issues. I created a JMenuBar, it's in the file: SlideViewMenu.java One of the operations is File->Close and another is File->Exit. The listener is in the SlideViewMenu.java file. The
-
After Effects not downloading from Download Manager
Having problems trying to download a Trial of After Effects. In the Download Assistant I am getting an error message: Error communicating with Adobe.com (Error 107). Restart Adobe Download Assistant and try to add the product again.
-
Avoid procedure or function calls between a SQL operation and an implicit cursor test
when i analyse this code with code expert