Which group by function to use in following case?
Table name: PVH
| Processid | Name | Timechanged | Value |
| 268436769 | filecount | 10/1/2008 2:59:01.006000 AM | 0 |
| 268436769 | filecount | 10/1/2008 2:45:33.004000 AM | 100 |
I want "value" where max(timechanged) and groupby appianprocessid and name …… that is "0"
How to get that using simple SQL? I tried following two approaces….
Select max(timechanged), value from pvh where appianprocessid=268436769 group by appianprocessid, name, value
This query returns me two values...
Select max(timechanged), max(value) from pvh where appianprocessid=268436769 group by appianprocessid, name
This
Thanks
Sandeep
Hello,
Try:
SELECT name, value, timechanged
FROM PVH p1
WHERE timechanged = (
SELECT MAX(timechanged)
FROM PVH p2
WHERE p1.appianprocessid = p2.appianprocessid)
WHERE appianprocessid = 268436769 ;Edited by: SeánMacGC on Jul 14, 2009 2:55 PM
And another way:
SELECT name, value, timchanged
FROM (
SELECT name, value, timechanged,
ROW_NUMBER() OVER (PARTITION BY appianprocessid ORDER BY timechanged DESC) row_num
FROM PVH)
WHERE appianprocessid = 268436769
AND row_num <= 1;And if the timechanged can have duplicate values for each appianprocessid, and you want all rows with the same MAX(appianprocessid), change ROW_NUMBER to RANK in that second query.
Similar Messages
-
Column Group Values Function without using Analytics?
I'm looking for a out-of-the-box Oracle SQL function that will visually group column values. (As shown in the Department column below).
I know that you can accomplish this using analytic lead/lag functions (also shown below), but I figure there must be another simpler, straight-forward function than this?
SELECT CASE
WHEN LAG (deptno)
OVER (PARTITION BY deptno
ORDER BY ename) IS NULL
THEN
deptno
END department,
ename,
empno
FROM scott.emp
ORDER BY deptno,
ename;
DEPARTMENT ENAME EMPNO
10 CLARK 7782
KING 7839
MILLER 7934
20 ADAMS 7876
FORD 7902
JONES 7566
SCOTT 7788
SMITH 7369
30 ALLEN 7499
BLAKE 7698
JAMES 7900
MARTIN 7654
TURNER 7844
WARD 7521Solution with model
select deptno ,empno,ename,ind
from emp
model
partition by ( deptno dept )
dimension by (row_number()over(partition by deptno order by empno) rn)
measures(empno,deptno , ename, 0 ind)ignore nav
rules(deptno[rn>1]=null,
ind[rn>1]= 1
)order by dept,ind
SQL> select deptno ,empno,ename,ind
2 from emp
3 model
4 partition by ( deptno dept )
5 dimension by (row_number()over(partition by deptno order by empno) rn)
6 measures(empno,deptno , ename, 0 ind)ignore nav
7 rules(deptno[rn>1]=null,
8 ind[rn>1]= 1
9 )order by dept,ind
10 /
DEPTNO EMPNO ENAME IND
10 7782 CLARK 0
7934 MILLER 1
7839 KING 1
20 7369 SMITH 0
7566 JONES 1
7902 FORD 1
7876 ADAMS 1
7788 SCOTT 1
30 7499 ALLEN 0
7900 JAMES 1
7844 TURNER 1
7698 BLAKE 1
7654 MARTIN 1
7521 WARD 1
4568 salim 0
15 rows selected.
SQL> Edited by: Salim Chelabi on Mar 31, 2009 3:33 PM -
Find out on which page a function is used?
Hi
is there any chance to find the page, where a certain function is used?
SlaviHi,
Why don't you amend the function to write the application page id to a table. A simple example
create table tst (page_id VARCHAR2(10));
CREATE OR REPLACE FUNCTION my_function RETURN NUMBER IS
tmpVar NUMBER;
pragma Autonomous_Transaction;
BEGIN
tmpVar := 0;
insert into tst values(V('APP_PAGE_ID'));
commit;
RETURN tmpVar;
END my_function;
At least then you can see which page is calling the function.
Regards
Paul -
How group by function/procedure used in function
i want to capture information in different table which extract by select statement like(select trans_date from bankAccount group by cust_id).
CTAS - Create Table As Select.
Example:
CREATE TABLE my_results
NOLOGGING AS
SELECT
trans_date
FROM bankAccount
GROUP BY
cust_idRefer to the [url http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm]Oracle® Database SQL Reference for details. -
To fetch data using group by function
Hi Guys,
I am having a table where it holds data with value with zero in one of the column and i need to fetch the records from the table using group by function but to display all the records if zero occurs in my table
for eg
table1
id,customer_name,country
0 sam aus
1 peter ind
1 peter ind
0 samy us
0 rayan nz
if i use select count(*),id from table1 group by id
i will get
count(*),id
3-0
1-2
but wat i need is like below
0 sam aus
0 samy us
0 rayan nz
2 peter ind
whenever zero is occurring i need to display all the records but group by should work for non zero recordsThe simplest way would be to have two queries and UNION them together. For example:
WITH test_data AS
( SELECT 0 AS id, 'sam' AS customer_name, 'aus' AS country FROM DUAL UNION ALL
SELECT 1 AS id, 'peter' AS customer_name, 'ind' AS country FROM DUAL UNION ALL
SELECT 1 AS id, 'peter' AS customer_name, 'ind' AS country FROM DUAL UNION ALL
SELECT 0 AS id, 'samy' AS customer_name, 'us' AS country FROM DUAL UNION ALL
SELECT 0 AS id, 'rayan' AS customer_name, 'nz' AS country FROM DUAL
SELECT cnt
, customer_name
, country
FROM ( SELECT id
, customer_name
, country
, COUNT(*) OVER (PARTITION BY id) AS cnt
, ROW_NUMBER() OVER (PARTITION BY id ORDER BY id) rn
FROM test_data
WHERE id != 0
WHERE rn = 1
UNION
SELECT id
, customer_name
, country
FROM test_data
WHERE id = 0
This gives the following results:
CNT CUSTO COU
0 rayan nz
0 sam aus
0 samy us
2 peter ind -
Which function is used for adding days to given month
which function is used for adding days to given month
Hi Jagrut,
Good ... Check out the following examples
<b>Get a date</b>
DATE_GET_WEEK Returns week for a date
WEEK_GET_FIRST_DAY Returns first day for a week
RP_LAST_DAY_OF_MONTHS Returns last day of month
FIRST_DAY_IN_PERIOD_GET Get first day of a period
LAST_DAY_IN_PERIOD_GET Get last day of a period
RP_LAST_DAY_OF_MONTHS Determine last day of month
<b>Date calculations</b>
DATE_COMPUTE_DAY Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.
DATE_IN_FUTURE Calculate a date N days in the future.
RP_CALC_DATE_IN_INTERVAL Add days/months to a date
RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date
SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates
MONTH_PLUS_DETERMINE Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.
DATE_CREATE Calculates a date from the input parameters:
Example: DATE_CREATE
CALL FUNCTION 'DATE_CREATE'
EXPORTING
anzahl_jahre = 1
anzahl_monate = 2
anzahl_tage = 3
datum_ein = '20010101'
IMPORTING
datum_aus = l_new_date.
Result:
l_new_date = 20020304
Example: MONTH_PLUS_DETERMINE
data: new_date type d.
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = -5 " Negative to subtract from old date, positive to add
olddate = sy-datum
IMPORTING
NEWDATE = new_date.
write: / new_date.
<b>Hollidays</b>
HOLIDAY_GET Provides a table of all the holidays based upon a Factory Calendar &/ Holiday Calendar.
HOLIDAY_CHECK_AND_GET_INFO Useful for determining whether or not a date is a holiday. Give the function a date, and a holiday calendar, and you can determine if the
date is a holiday by checking the parameter HOLIDAY_FOUND.
Example: HOLIDAY_CHECK_AND_GET_INFO
data: ld_date like scal-datum default sy-datum,
lc_holiday_cal_id like scal-hcalid default 'CA',
ltab_holiday_attributes like thol occurs 0 with header line,
lc_holiday_found like scal-indicator.
CALL FUNCTION 'HOLIDAY_CHECK_AND_GET_INFO'
EXPORTING
date = ld_date
holiday_calendar_id = lc_holiday_cal_id
WITH_HOLIDAY_ATTRIBUTES = 'X'
IMPORTING
HOLIDAY_FOUND = lc_holiday_found
tables
holiday_attributes = ltab_holiday_attributes
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
DATE_AFTER_RANGE = 2
DATE_BEFORE_RANGE = 3
DATE_INVALID = 4
HOLIDAY_CALENDAR_ID_MISSING = 5
HOLIDAY_CALENDAR_NOT_FOUND = 6
OTHERS = 7.
if sy-subrc = 0 and
lc_holiday_found = 'X'.
write: / ld_date, 'is a holiday'.
else.
write: / ld_date, 'is not a holiday, or there was an error calling the function'.
endif.
Checking dates
DATE_CHECK_PLAUSIBILITY Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems.
Converting dates
DATE_CONV_EXT_TO_INT Conversion of dates to SAP internal format e.g. '28.03.2000' -> 20000328 Can also be used to check if a date is valid ( sy-subrc <> 0 )
Function to return literal for month
he table you want to use is T247. You can also use the function MONTH_NAMES_GET.
You can also try table T015M. It has the month number in it's key.
Formatting
DATUMSAUFBEREITUNG Format date as the user settings
Other
MONTH_NAMES_GET It returns all the month and names in repective language.
Good Luck and thanks
AK -
I want to get an output using group by function of there is no data in the table to display a particular value
for eg:
SELECT TRUNC(updated_date) DATE1 , COUNT(1) COUNT FROM table
where TRUNC(updated_date) >=TRUNC(SYSDATE-18) AND TRUNC(updated_date) <=TRUNC(SYSDATE)
GROUP BY TRUNC(updated_date)
ORDER BY TRUNC(updated_date) DESC;
DATE1 COUNT
6/16/2012 14208
6/15/2012 307825
6/14/2012 172988
6/6/2012 138790
6/5/2012 167562
6/4/2012 51870
6/2/2012 130582
6/1/2012 239806
But i need the missed out date i.e 6/3/2012 - 0, 6/7/2012 - 0 to be displayed since there is no data on the repective dates.Hi,
You can only display things that are in a table (or result set, but from now on, I'll just say table), or that can be derived from a table. If you want to display dates that are not in your table, then you have to get them from another table, or derive them from some table.
Some people actually keep tables of possible dates for queries like this. In this case, all you need is a table of the last 19 dates, ending with today. That's easy to derive from dual:
WITH all_dates AS
SELECT TRUNC (SYSDATE) - LEVEL AS date1
, TRUNC (SYSDATE) + 1 - LEVEL AS date2
FROM dual
CONNECT BY LEVEL <= 19
SELECT a.date1
, COUNT (x.updated_date) AS count
FROM all_dates a
LEFT OUTER JOIN table_x x ON x.updated_date >= a.date1
AND x.updated_date < a.date2
GROUP BY a.date1
ORDER BY a.date1
;If you'd care to post CREATE TABLE and INSERT statements for some sample data, and the results you want from that data, then I could test this. -
How to Use a Group by Function
Hi Gurus,
I have Requirment where i need to use the group by function to one column
below is my query , can anyone help how to use the group by for the column OCCASIONALS_QT_STATUS.
below is giving me the error not a group by expression
select distinct source_id,OCCASIONALS_QT_STATUS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where OCCASIONALS_QT_STATUS = 'QTS'
and source_id = gdoc.source_id
) OccasionalsQTS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NOTQTS'
and source_id = gdoc.source_id
) OccasionalsNOTQTS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NTKNWN'
and source_id = gdoc.source_id
) OccasionalsNOTKNWN
from gen_dcsf_occasionals_count gdoc group by OCCASIONALS_QT_STATUS;
any inputs on this is highly appreciable
Thanks in advance909577 wrote:
Hi Gurus,
I have Requirment where i need to use the group by function to one column
below is my query , can anyone help how to use the group by for the column OCCASIONALS_QT_STATUS.
below is giving me the error not a group by expression
select distinct source_id,OCCASIONALS_QT_STATUS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where OCCASIONALS_QT_STATUS = 'QTS'
and source_id = gdoc.source_id
) OccasionalsQTS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NOTQTS'
and source_id = gdoc.source_id
) OccasionalsNOTQTS,
(SELECT sum(head_count)
FROM gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NTKNWN'
and source_id = gdoc.source_id
) OccasionalsNOTKNWN
from gen_dcsf_occasionals_count gdoc group by OCCASIONALS_QT_STATUS;
any inputs on this is highly appreciable
Thanks in advanceFor your own sanity, you should format your code to make it more readable
For the sanity of those from whom you seek help, you should preserve that formatting with the code tags:
select
distinct source_id,
OCCASIONALS_QT_STATUS,
(SELECT
sum(head_count)
FROM
gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'QTS' and
source_id = gdoc.source_id
) OccasionalsQTS,
(SELECT
sum(head_count)
FROM
gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NOTQTS' and
source_id = gdoc.source_id
) OccasionalsNOTQTS,
(SELECT
sum(head_count)
FROM
gen_dcsf_occasionals_count
where
OCCASIONALS_QT_STATUS = 'NTKNWN' and
source_id = gdoc.source_id
) OccasionalsNOTKNWN
from
gen_dcsf_occasionals_count gdoc
group by
OCCASIONALS_QT_STATUS; -
Can i use Lead function with Group by function
I could use this query and get right ouput since i define product id =2000
select product_id, order_date,
lead (order_date,1) over (ORDER BY order_date) AS next_order_date
from orders
where product_id = 2000;
But can i run this query by Group by Function
for example
select product_id, order_date,
lead (order_date,1) over (ORDER BY order_date) AS next_order_date
from orders
group by product_id ;
since data would be like and i need
Product_id order Date
2000 1-jan-09
2000 21-jan-09
3000 13-jan-09
3000 15-jan-09
4000 18-jan-09
4000 19-jan-09
output would be like for eg
Product_id order Date Next_date
2000 1-jan-09 21-jan-09
3000 13-jan-09 15-jan-09
4000 18-jan-09 19-jan-09Thanks everybody for ur help
i could exactly mention what i requred
create table SCHEDULER
( REF VARCHAR2(10),
NO NUMBER ,
PORT VARCHAR2(10),
ARRIVAL DATE ,
DEPARTURE DATE
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',1,'KUWAIT','1-Sep-09','02-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',2,'INDIA','5-Sep-09','07-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',3,'COLUMBO','8-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',4,'IRAN','10-Sep-09','12-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',5,'IRAQ','14-Sep-09','15-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',6,'DELHI','17-Sep-09','19-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0677',7,'POLAND','21-Sep-09','23-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',1,'INDIA','5-Sep-09','07-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',2,'COLUMBO','8-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',3,'IRAN','10-Sep-09','12-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',4,'IRAQ','14-Sep-09','15-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',5,'DELHI','17-Sep-09','19-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',6,'POLAND','21-Sep-09','23-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA0678',7,'GOA','1-Oct-09','02-Oct-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2372',1,'INDIA','1-Sep-09','02-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2372',2,'KERALA','3-Sep-09','03-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2372',3,'BOMBAY','4-Sep-09','04-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2373',1,'INDIA','5-Sep-09','06-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2373',2,'ANDHERI','6-Sep-09','07-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2376',1,'INDIA','5-Sep-09','07-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2420',1,'INDIA','5-Sep-09','06-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2420',2,'ANDHERI','7-Sep-09','08-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2420',3,'BURMA','10-Sep-09','11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2420',4,'BENGAL','11-Sep-09','12-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2445',1,'INDIA','4-Sep-09','05-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2445',2,'BURMA','7-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2498',1,'BENGAL','8-Sep-09','08-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2498',2,'COCHIN','11-Sep-09','11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2498',3,'LANKA','12-Sep-09','12-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2498',4,'COLUMBO','13-Sep-09','15-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2498',5,'INDIA','17-Sep-09','18-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2505',1,'COLUMBO','5-Sep-09','06-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2505',2,'GOA','8-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2505',3,'INDIA','13-Sep-09','15-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2510',1,'INDIA','4-Sep-09 06-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2510',2,'BENGAL','8-Sep-09 09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2510',3,'GOA','10-Sep-09 11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2513',1,'INDIA','7-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2513',2,'USA','11-Sep-09','11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2513',3,'UK','12-Sep-09','13-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2520',1,'INDIA','4-Sep-09','06-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2520',2,'BENGAL','8-Sep-09','09-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2520',3,'GOA','10-Sep-09','11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2526',1,'INDIA','5-Sep-09','07-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2526',2,'DUBAI','10-Sep-09','11-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2526',3,'GOA','13-Sep-09','15-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2526',4,'OMAN','17-Sep-09','18-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2526',5,'INDIA','19-Sep-09','20-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2527',1,'BURMA','7-Sep-09','08-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2527',2,'INDIA','9-Sep-09','10-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2527',3,'ANDHERI','10-Sep-09','16-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2532',1,'SHARJAH','3-Sep-09','04-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2532',2,'AEDXB','5-Sep-09','05-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2533',1,'AESHJ','2-Sep-09','02-Sep-09');
INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
VALUES('VA2533',2,'INDIA','3-Sep-09','03-Sep-09');
COMMIT;
Suppose these records shows the REF travelling from one location to another with respect to date
We need to find out each REF GROUP WISE AND THE DATE OF TRAVELLING FOR SPECIFIED location travelling IE from STARTING FROM INDIA AND ENDING TO GOA
OUTPUT SHOULD BE LIKE DATA SHOWN BELOW
FROM LOCATION TO LOCATION
REF , NO , PORT , ARRIVAL ,DEPARTURE , REF , NO , PORT , ARRIVAL , DEPARTURE
VA0678 1 INDIA 5-Sep-09 07-Sep-09 VA0678 7 GOA 1-Oct-09 02-Oct-09
VA2510 1 INDIA 4-Sep-09 06-Sep-09 VA2510 3 GOA 10-Sep-09 11-Sep-09
VA2520 1 INDIA 4-Sep-09 06-Sep-09 VA2520 3 GOA 10-Sep-09 11-Sep-09
VA2526 1 INDIA 5-Sep-09 07-Sep-09 VA2526 3 GOA 13-Sep-09 15-Sep-09
---------------------------------------------------------------------------------------------------------------------------------------------------------------- -
I want to get an output using group by function of there is no data in the table to display a particular value
for eg:
SELECT TRUNC(updated_date) DATE1 , COUNT(1) COUNT FROM table
where TRUNC(updated_date) >=TRUNC(SYSDATE-18) AND TRUNC(updated_date) <=TRUNC(SYSDATE)
GROUP BY TRUNC(updated_date)
ORDER BY TRUNC(updated_date) DESC;
DATE1 COUNT
6/16/2012 14208
6/15/2012 307825
6/14/2012 172988
6/6/2012 138790
6/5/2012 167562
6/4/2012 51870
6/2/2012 130582
6/1/2012 239806
But i need the missed out date i.e 6/3/2012 - 0, 6/7/2012 - 0 to be displayed since there is no data on the repective dates.Please post here {forum:id=75}
-
Which SQL function to use to get previous month's data?
Hi
The reporting need: Display of two month's payroll run results....current and previous (based on the parameter passed) in Oracle Discoverer.
Data source: A table in which run result values are stored. Of course to be linked to number of other tables.
Can somebody guide me on which SQL function to use to get the data for previous month?
Secondly, as Discoverer does not support parameters, I cannot put parameter in the query itself. I'll be applying parameter later while generating my report.
Please advice.
Thanks and regards,
AparnaIt's not very clear in my head... but you can try :
SQL> select * from test;
ENAM SAL DT
TOTO 1000 30/05/06
TOTO 1001 20/04/06
TOTO 1002 11/03/06
TATA 2000 30/05/06
TATA 1500 20/04/06
TUTU 3500 30/05/06
6 rows selected.
SQL> select ename, dt, sal currmonth,
case when trunc(lag(dt,1,dt) over (partition by ename order by dt),'MM') = trunc(add_months(dt,-1),'MM')
then lag(sal,1,sal) over (partition by ename order by dt)
else null end prevmonth
from test
SQL> /
ENAM DT CURRMONTH PREVMONTH
TATA 20/04/06 1500
TATA 30/05/06 2000 1500
TOTO 11/03/06 1002
TOTO 20/04/06 1001 1002
TOTO 30/05/06 1000 1001
TUTU 30/05/06 3500
6 rows selected.
SQL>
SQL> Nicolas.
Just an additional question : do the previous month is current month-1, or is there hole in month suite (e.g. the previous month can be current month-2) ?
Message was edited by:
N. Gasparotto -
Which are function modules used to convert into XML format in SAP 4.6c Ver
which are function modules used to convert into XML format in SAP 4.6c Ver
Hi,
check this program , I think this will help you
TYPE-POOLS: ixml.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
data : itab like catsdb occurs 100 with header line.
data : file_location type STRING.
data : file_name like sy-datum.
data : file_create type STRING.
file_name = sy-datum .
file_location = 'C:\xml\'.
concatenate file_location file_name into file_create.
concatenate file_create '.XML' into file_create.
DATA: l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
select * from catsdb into table itab.
append itab .
CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
I_XML_DOC_NAME =
IMPORTING
PE_BIN_FILESIZE = l_xml_size
TABLES
i_tab_sap_data = itab
CHANGING
I_TAB_CONVERTED_DATA = l_xml_table
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 24
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = file_create
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
write : 'INTERNAL TABLE DATA IS SUCCESSFULLY DOWNLOADED TO LOCATION', file_create .
Thanks. -
How to check which function was used in a function based index.
Hi how can i check which function was used in a function based index created on a column.
ThanksHi,
What is your requirement... !!
Bascially performing a function on an indexed column in the where clause of a query guaranteed an index would not be used. From Oracle 8i onwards introduced Function Based Indexes to counter this problem.
Any how check this..you will get an idea..
http://www.akadia.com/services/ora_function_based_index_2.htm
http://www.oracle-base.com/articles/8i/FunctionBasedIndexes.php
-Pavan Kumar N -
Hi everybody!
I have the issue that a colleague of mine synchronized a whole bunch of ldap-groups into vibe. The Problem is that I want to clean the system up now, but I don't know which groups are in use and which are not. Is there a way to see a list of used groups or something like that?
greetings lJacknot directly. you can look in the access rights of a folder which group is connected to it. otherwise you have to build a sql script on database with the id of groups relating to the binder_id of a workspace. depending how large your installation is.
-
How to specify which version of a function to use
I tried to do what it said, but that resulted in error
PowershellPS C:\WINDOWS\system32> Import-dscResource -ModuleName @{ModuleName="xPSDesiredStateConfiguration";ModuleVersion="3.4.0.0"}Import-dscResource : The term 'Import-dscResource' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ Import-dscResource -ModuleName @{ModuleName="xPSDesiredStateConfigura ...+ ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Import-dscResource:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
(Btw: The Edge Web browser doesn't show the formatting toolbar in these text editors... I switched to IE to write this)I have this script and the problem is, there's two versions of xPSDesiredStateConfiguration in the wildTextconfiguration HTTPPullServer{ # Modules must exist on target pull server Import-DSCResource -ModuleName xPSDesiredStateConfiguration Node dc { WindowsFeature DSCServiceFeature { Ensure = "Present" Name = "DSC-Service" } WindowsFeature IISConsole { Ensure = "Present" Name = "Web-Mgmt-Console" } xDscWebService PSDSCPullServer { Ensure = "Present" EndpointName = "PSDSCPullServer" Port = 8080 PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" CertificateThumbPrint = "AllowUnencryptedTraffic" ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" ConfigurationPath = "$env:PROGRAMFILES\...
(Btw: The Edge Web browser doesn't show the formatting toolbar in these text editors... I switched to IE to write this)I have this script and the problem is, there's two versions of xPSDesiredStateConfiguration in the wildTextconfiguration HTTPPullServer{ # Modules must exist on target pull server Import-DSCResource -ModuleName xPSDesiredStateConfiguration Node dc { WindowsFeature DSCServiceFeature { Ensure = "Present" Name = "DSC-Service" } WindowsFeature IISConsole { Ensure = "Present" Name = "Web-Mgmt-Console" } xDscWebService PSDSCPullServer { Ensure = "Present" EndpointName = "PSDSCPullServer" Port = 8080 PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" CertificateThumbPrint = "AllowUnencryptedTraffic" ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" ConfigurationPath = "$env:PROGRAMFILES\...
Maybe you are looking for
-
Java RMI & XML parsing.
I'm new to Java so any help is greatly appreciated. I trying to develop a distributed application using Java RMI that allows a user to enter a users name and be returned their email address and telephone number. The details of users will be stored in
-
Hi i have 4gb in my mac.I want to increase to 8 gb
-
SQL Loader - Loading Text File into Oracle Table that has carriage returns
Hi All, I have a text file that I need to load into a table in Oracle using SQL Loader. I'm used to loading csv or comma delimited files into Oracle so I'm not sure what the syntax is when it comes to loading a text file that essentially has one valu
-
Hi expert, we have two instance in our production. web service are implemented in both instance http://instance1.demo.com/bpm/update/process/StartProcessIn?wsdl&mode=ws_policy http://instance2.demo.com/bpm/update/process/StartProcessIn?wsdl&mode=ws_p
-
How download cs6 in creative cloud ?
I was downloading creative cloud. All worked well except the PHOTOSHOP CS6 - the message is : " download seems damaged, try again ( -60 ). I tried but with the same results. What I should do ?