Apex SQL question - weeks of the month
I have a sql question.I want to create a dynamic list.
If the user select may2009, then I want a dynamic list of show
04/27/2009-05/03/2009
05/04/2009-05/10/2009
05/11/2009-05/17/2009
05/18/2009-05/24/2009
05/25/2009-05/31/2009
If the user selects Jun 2009, then the list will be
06/01/2009-06/07/2009
06/08/2009-06/14/2009
06/15/2009-06/21/2009
06/22/2009-06/28/2009
06/29/2009-07/05/2009
Thank you.
Using this SQL statement, you can get this list:
SELECT w_start || ' - ' || w_end d, w_start r
FROM (SELECT (week_start_list + (LEVEL - 1) * 7) + 1 w_start,
week_start_list + (LEVEL) * 7 w_end
FROM (SELECT TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
'mm'
),
'IW'
) week_begin,
TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
'mm'
) m_begin,
TO_CHAR
(TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm'),
'd'
) day_month_begin,
TO_CHAR
(TRUNC (ADD_MONTHS (TO_DATE (:my_date,
'dd.mm.yyyy'
),
1
),
'mm'
),
'IW'
) week_end,
TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
1
),
'mm'
) m_end,
TO_CHAR
(TRUNC (ADD_MONTHS (TO_DATE (:my_date,
'dd.mm.yyyy'
),
1
),
'mm'
),
'd'
) day_month_end,
TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
'mm'
)
- TO_NUMBER
(TO_CHAR (TRUNC (TO_DATE (:my_date,
'dd.mm.yyyy'
),
'mm'
),
'd'
)
) week_start_list,
TRUNC
(ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
1
),
'mm'
)
+ TO_NUMBER
(TO_CHAR
(TRUNC
(ADD_MONTHS (TO_DATE (:my_date,
'dd.mm.yyyy'
),
1
),
'mm'
),
'd'
)
)
- 1 week_end_list
FROM DUAL)
CONNECT BY LEVEL <=
(SELECT TO_NUMBER
(TO_CHAR
(TRUNC
(ADD_MONTHS (TO_DATE (:my_date,
'dd.mm.yyyy'
),
1
),
'mm'
),
'IW'
)
)
- TO_NUMBER
(TO_CHAR (TRUNC (TO_DATE (:my_date,
'dd.mm.yyyy'
),
'mm'
),
'IW'
)
)
FROM DUAL))
It is a question of SQL and has nothing to do with the Apex.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
-------------------------------------------------------------------
Tags: Database
Similar Questions
-
Hey,.
I try to display the weeks of the month based on values and a date. I have a select statement that displays vertical to results, but I would like that they horizontally with the listed weeks. Below are the create table and insert instructions to help. Once the start dates and end Dates are entered for one month, then the weeks should display with the counts for each Type Emp values and totals for each Type of Emp showing also. Any help is appreciated. Thanks for taking a peek at my question.
-Toad for Oracle 12.5
CREATE TABLE TBL_EMP
EMP_ID NUMBER NOT NULL,
FK_EMP_TYPE_ID NUMBER ,
EMP_DATE DATE
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(1, 100, TO_DATE('10/14/2014', 'MM/DD/YYYY'));
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(2, 200, TO_DATE('10/12/2014', 'MM/DD/YYYY'));
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(3, 200, TO_DATE('10/8/2014', 'MM/DD/YYYY'));
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(4, 300, TO_DATE('10/15/2014', 'MM/DD/YYYY'));
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(5, 100, TO_DATE('10/12/2014', 'MM/DD/YYYY'));
INSERT INTO TBL_EMP
()EMP_ID FK_EMP_TYPE_ID EMP_DATE( )
(6, 100, TO_DATE('9/9/2014', 'MM/DD/YYYY'));
SELECT * DE TBL_EMP;
-Can I display the vertical weeks but I would like that they horizontal
SELECT 'WEEK ' || (TO_CHAR (EMP_DATE + 4, 'W')) WEEKS,
FK_EMP_TYPE_ID ,
COUNT (FK_EMP_TYPE_ID) AS EMP_TYPE_COUNT
FROM TBL_EMP
WHERE EMP_DATE BETWEEN TO_DATE ( :P10_START_DATE, 'MM/DD/YYYY')
AND NVL (TO_DATE ( :P10_END_DATE, 'MM/DD/YYYY'), SYSDATE)
GROUP BY 'WEEK ' || (TO_CHAR (EMP_DATE + 4, 'W')), FK_EMP_TYPE_ID
ORDER BY WEEKS;
-The values to enter for months
-P10_START_DATE 10/01/2014
-P10_END_DATE 31/10/2014
-Results
WEEK 2 200 1
WEEK 3 100 2
WEEK 3 200 1
WEEK 3 300 1
SELECT FK_EMP_TYPE_ID , COUNT (*)
FROM TBL_EMP
WHERE EMP_DATE BETWEEN TO_DATE ( :P10_START_DATE ' MM/DD/YYYY '( )
AND NVL (TO_DATE ( :P10_END_DATE, 'MM/DD/YYYY'), SYSDATE)
GROUP BY FK_EMP_TYPE_ID
ORDER BY FK_EMP_TYPE_ID ASC;
-Results
FK_EMP_TYPE_ID COUNT(*)
100 2
200 2
300 1
-Results and horizontal display I want
FK_EMP_TYPE_ID WEEK 1 WEEK 2 WEEK 3 WEEK 4 TOTALS
100 0 0 2 0 2
200 0 1 1 0 2
300 0 0 1 0 1
Hello
Select
Here's one way:
WITH relevant_data AS
(
SELECT fk_emp_type_id
TO_CHAR (emp_date + 4, 'W') AS week_num - see note below
OF tbl_emp
WHERE the emp_date BETWEEN NVL (TO_DATE (: p10_start_date, ' MM/DD/YYYY'))
SYSDATE - TRUNC (SYSDATE) or
)
AND NVL (TO_DATE (: p10_end_date, ' MM/DD/YYYY'))
SYSDATE
)
)
SELECT p
week_1 + week_2 + week_3 + week_4 + week_5 AS totals
OF relevant_data
PIVOT (COUNT (*)
FOR week_num IN ('1' AS week_1
'2' AS week_2
'3' AS week_3
'4' AS week_4
'5' AS week_5
)
) p
ORDER BY fk_emp_type_id
;
Are you sure you want to add 4 days before calculating the week number? If you're wondering the month of October 2014, for example, '1' of the week would include 1-3 October and from 28 to 31 October. (4 days after October 28 is November 1, which is 1 week of November).
-
get the first week of the month
Hello
How to get the first week of the month of request
I tried this, but not gwtting
SELECT THE DOUBLE TO_CHAR('09/30/2007','W')
Thank you
Published by: 896398 on January 18, 2012 03:17SQL> select to_char(to_date('07-12-2008', 'DD-MM-YYYY'), 'W') from dual; T - 1 SQL> select to_char(to_date('14-12-2008', 'DD-MM-YYYY'), 'W') from dual; T - 2 SQL> select to_char(to_date('23-12-2008', 'DD-MM-YYYY'), 'W') from dual; T - 4
HTH
Kind regards
NORTH CAROLINA -
start date for each week of the month
Dear members
How can I find double, the start date of each week of the month in a year.
beginning of the week is the word "Monday".
year month week day date
----------------------------------------------------------------------------------------
Monday, January 3, 2011 JAN 1, 2011
2011 2 JAN Monday, January 10, 2011
Monday, January 17, 2011 January 3, 2011
JAN 4 2011 on Monday, January 24, 2011
2011 to January 5 Monday, January 31, 2011
Thank you
teefuHello
You can use this:
with t as (select to_date ('01/01/2011', 'DD/MM/YYYY') start_date from dual) select date_calc from ( select start_date, (level-1)*7+trunc (start_date , 'D')+1 as date_calc from t connect by level <=53) where trunc(date_calc,'YYYY')=trunc(start_date,'YYYY') ;
Kind regards
Sylvie -
How to calculate this column (the last week of the month)?
I have a request where it shows a few months of calculations of sage
ex. This report is for Dec-2010
statement line. A reduced rate. Approved rate. Last week declined the rate |
-------------------------
Asia report | ------20%----- | -----45%-------- | --------4%------ |
Africa report | ------44% -----| -----21%-------- | ------12%-------|
I'm figuring the column rate declined last week . The logic is simply not coming to my mind.
Can someone suggest me how can I calculate this?We'll see. This report at any time after the previous month running has closed...
(1) TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE) will give you the last day of the previous month.
(2) TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) will give you the Saturday before the last week of the month.
(3) TIMESTAMPADD (SQL_TSI_DAY, 1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE))) will give you the Sunday of the last week of the previous month.
Now that you have the start of the last day of the previous week, you can create your filter... It will be "(between 3) and 1)" above... "
-
How to get the Date in month based on week of the month.
Hi gurus,
I have provided.
Quarter (Q) = > 1 (Jan - Mar), 2 (April-June), 3 (July-September), 4 (October-December).
Months (M) = > Jan = 1, Feb = 2, Mar = 3 in the 1st quarter.
ARP = 1, may = 2, Jun = 3 in the 2nd quarter,
Jul = 1, August = 2, Ms = 3 in Q3,
Oct 1 Nov = = 2, Dec = 3 in the 4th quarter
If I give Q = 3, M = 3, W = 1 day = Fri so I get 6-Sep-13
Similarly, if I give Q = 2, M = 1, O = 3, day = game so I get 18 April 13.
Could someone help me higher and higher.
Concerning
Sanjeev
Believing that when you say you want to say that it is 1 - 5 in a month with the 1st day of the month as the beginning of the 1st week of the week. You can try this.
SQL > t
2 as
(3)
4. Select q 3, 3 m, 1 w, 'Ven' d
5 double
6 union
7 all the
8. Select q 2, 1 m, 3 w, d 'game '.
9 double
10)
11. Select q, m, w, d, d_day
12 years of)
13 select y + (level - 1) d_day
14, ceil (extract (day of cast (y + (level - 1) as timestamp)) / 7) week_7_day
15 , t.*
16 of)
17 select add_months (trunc (sysdate, 'year') (q * 3-3) +(m-1)) y
18 , t.*
19 t
20 ) t
21 connect
22 by level<= last_day(y)="" -="" y="" +="">=>
23 and prior y = y
dbms_random.value (24 and prior) is not null
25 )
where the 26 w = week_7_day
27 and substr (to_char (d_day 'day'), 1, 3) = lower (d);Q M W D D_DAY
---------- ---------- ---------- --- ---------
2 1 3 Friday 18 April 13
3 3 1 Fri 06-SEP-13SQL >
-
Select SQL - last day of the month, a year from now
Hello
How do we get the last day of the month, a year from now.
For example-sysdate-12/2/2009
Result - 31/12/2009
Thank youHello
SELECT LAST_DAY ( ADD_MONTHS ( SYSDATE , 12 ) ) FROM dual;
Remember, all DATEs, including the results of this query, include the hours minutes and seconds.
The hours, the minutes and the seconds returned by the above expression are the same as SYSDATE: If you run it at 15:43:30 today, it returns 15:43:30 on December 31, 2010. This can be important if you want to use an expression like this as the cut-off point in a WHERE clause. -
calculation of the week and the month of the column date
I have 3 data as column
I need to convert it to 4 columnswith tab as ( select 'Topshop' brand, '10-JUL-11' deliverydate, '100' qty from dual union all select 'Topshop' brand, '10-JUL-11' deliverydate, '400' qty from dual union all select 'NewSita' brand, '11-JUL-11' deliverydate, '200' qty from dual union all select 'LaGress' brand, '12-JUL-11' deliverydate, '300' qty from dual union all select 'LaGress' brand, '10-AUG-11' deliverydate, '100' qty from dual union all select 'LaGress' brand, '11-AUG-11' deliverydate, '200' qty from dual union all select 'Topshop' brand, '12-AUG-11' deliverydate, '300' qty from dual union all select 'NewSita' brand, '10-SEP-11' deliverydate, '100' qty from dual union all select 'Topshop' brand, '11-SEP-11' deliverydate, '200' qty from dual union all select 'NewSita' brand, '12-SEP-11' deliverydate, '300' qty from dual ) select * from tab
Brand | Month | Week (start date). Amount (sum)
Please let me know what are the options I have, in particular the calculation of date and time functions available to solve these problems.
Thank you
w\Check this box
with tab as
(
Select the option 'Topshop' brand, July 10, 11 'deliverydate, ' 100' qty of any union double
Select the option 'Topshop' brand, July 10, 11 'deliverydate, ' 400' qty of any union double
Select the option "NewSita" brand, 11 July 11 'deliverydate, ' 200' qty of any union double
Select "brand the LaGress, 12 July 11' deliverydate, '300' qty of union double all the»
Select "brand the LaGress, 10 Aug 11' deliverydate, '100' qty of union double all the»
Select "brand the LaGress, 11 Aug 11' deliverydate, '200' qty of union double all the»
Select the option 'Topshop' brand, 12 Aug 11 'deliverydate, ' 300' qty of any union double
Select the brand 'NewSita',' 10-SEP-11 deliverydate, '100' qty of all double union
Select the option 'Topshop' brand,' 11-SEP-11 deliverydate, '200' qty of any union double
Select the option "NewSita" brand, deliverydate, '300' qty of the double' 12-SEPT-11
) select the brand, deliverydate, NEXT_DAY (to_date (deliverydate, 'DD-MON-yy'), "LUN")-7, Qty tab. -
PL/SQL LOOP or INSERT the MONTH
I have a table which has start_date and end_date for each line record but not individual for each month. For example, a folder may have payment of 6 months with the start date - '20100101' to end_date 20100630.
I need to know the payment every month for recon.
I want to add this month field and keep everything exactly the same as what is in the table.
The example above, to add
January 1, 2010... <-all otherwise same
FEBRUARY 1, 2010...
|
|
|
01-JUN-2010 ..........................................................
The useful fields are start_date and end_date, NO_OF_MONTHS1, NO_MONTHS_2. Somethimes, NO_MONTH1, and NO_MONTHS_2 stand. Normally when they differ, one is 00.
-oracle 10g
-DROP TABLE PAYMENTS;
CREATE TABLE PAYMENTS
(
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
NUMBER AMOUNT
);
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S001', ' 06 ', '06', '20', '20100101',' 20100630', 30');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S001', ' 04 ', '04', '12', '20090101',' 20090430', 50');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C002', 'S001', ' 02 ', '02', '20', '20090801',' 20100930', 100');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C002', 'S002', ' 02 ', '02', '20', '20090801',' 20100930', 100');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S002', ' 01 ', '01', '12', '20090101',' 20090131', 50');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S001', ' 00 ', '04', '18', '20090101',' 20090430', 50');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S003', ' 00 ', '02', '12', '20090501',' 20090731', 50');
INSERT INTO PAYMENTS (CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('C001', 'S004', ' 01 ', '01', '12', '20090101',' 20090131', 50');
commit;
The RESULTS should be something like
CREATE TABLE PAIEMENTS1
(
DATE OF ELIGIBLE_MONTH,
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
NUMBER AMOUNT
);
commit;
-HERE'S AN EXAMPLE OF HOW THE SOLUTION SHOULD COMEOUT TO THE 3 FIRST RECORD IN TABLE ABOVE
-first record in the table above, it should create 6 rows and apply eligible_month
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (JANUARY 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (FEBRUARY 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
INSERT INTO VALUES OF PAYMENTS (ELIGIBLE_MONTH, CMPNY S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, QUANTITY) (MARCH 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (APRIL 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (MAY 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
INSERT INTO VALUES OF PAYMENTS (ELIGIBLE_MONTH, CMPNY S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, QUANTITY) (JUNE 1, 2010 ', 'C001', 'S001', '06', '06', '20', '20100101', '20100630',' 30');
-IT SHOULD CREATE 4 ROWS
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (JANUARY 1, 2009 ","C001","S001', '04', '04', '12', '20090101', '20090430',' 50' ");
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (FEBRUARY 1, 2009 ', 'C001', 'S001', '04', '04', '12', '20090101', '20090430',' 50');
INSERT INTO VALUES OF PAYMENTS (ELIGIBLE_MONTH, CMPNY S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, QUANTITY) (MARCH 1, 2009 ', 'C001', 'S001', '04', '04', '12', '20090101', '20090430',' 50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (APRIL 1, 2009 ', 'C001', 'S001', '04', '04', '12', '20090101', '20090430',' 50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES (AUGUST 1, 2010 ', "C002', 'S001', '02', '02', '20', '20100801', '20100930',' 100');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY, S_ID, NO_MONTHS_1, NO_MONTHS_2, START_DATE, END_DATE, AMOUNT) VALUES ('01-SEP-2010', "C002', 'S001', '02', ' 02', '20', '20100801',' 20100930 ', ' 100');Thank you.
I think that's what you're after.
As a cautionary tale, store the date information in the STRINGS is very bad. As it is to store (pure digital) digital data in STRINGS.
Use the data types for the job.
select add_months( to_date(p.start_date, 'YYYYMMDD') , t.column_value - 1) as ELIGIBLE_MONTH, p.CMPNY, p.S_ID, p.NO_MONTHS_1, p.NO_MONTHS_2, p.adj_code, p.START_DATE, p.END_DATE, p.AMOUNT from payments p, table ( cast ( multiset ( select level from dual connect by level <= months_between(to_date(p.end_date, 'YYYYMMDD'), to_date(p.start_date, 'YYYYMMDD')) +1 ) as sys.OdciNumberList ) ) t order by p.cmpny, p.s_id; ELIGIBLE_MONTH CMPN S_ID NO NO ADJ_C START_DA END_DATE AMOUNT -------------------- ---- ---- -- -- ----- -------- -------- ------------------ 01-JAN-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-FEB-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-MAR-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-APR-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-MAY-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-JUN-2010 12 00:00 C001 S001 06 06 20 20100101 20100630 30 01-JAN-2009 12 00:00 C001 S001 04 04 12 20090101 20090430 50 01-FEB-2009 12 00:00 C001 S001 04 04 12 20090101 20090430 50 01-MAR-2009 12 00:00 C001 S001 04 04 12 20090101 20090430 50 01-APR-2009 12 00:00 C001 S001 04 04 12 20090101 20090430 50 01-APR-2009 12 00:00 C001 S001 00 04 18 20090101 20090430 50 01-MAR-2009 12 00:00 C001 S001 00 04 18 20090101 20090430 50 01-FEB-2009 12 00:00 C001 S001 00 04 18 20090101 20090430 50 01-JAN-2009 12 00:00 C001 S001 00 04 18 20090101 20090430 50 01-JAN-2009 12 00:00 C001 S002 01 01 12 20090101 20090131 50 01-JUL-2009 12 00:00 C001 S003 00 02 12 20090501 20090731 50 01-JUN-2009 12 00:00 C001 S003 00 02 12 20090501 20090731 50 01-MAY-2009 12 00:00 C001 S003 00 02 12 20090501 20090731 50 01-JAN-2009 12 00:00 C001 S004 01 01 12 20090101 20090131 50 01-JAN-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-JUN-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-JUL-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-AUG-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-SEP-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-APR-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-MAY-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-FEB-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-MAR-2010 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-AUG-2009 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-SEP-2009 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-OCT-2009 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-NOV-2009 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-DEC-2009 12 00:00 C002 S001 02 02 20 20090801 20100930 100 01-MAY-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-JUN-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-JUL-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-AUG-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-SEP-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-AUG-2009 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-SEP-2009 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-MAR-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-FEB-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-JAN-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-DEC-2009 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-NOV-2009 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-OCT-2009 12 00:00 C002 S002 02 02 20 20090801 20100930 100 01-APR-2010 12 00:00 C002 S002 02 02 20 20090801 20100930 100 47 rows selected. Elapsed: 00:00:00.03 TUBBY_TUBBZ?
-
SQL question, perhaps with the analytical functions?
I have a small problem:
I have a table with:
DAY_ID, PAGE_ORDER, SID, TIME, CONTENT.
I want only to the rank (min) of lines with the same content when there is more than
the one with the same content that follows.
The data are:
DAY PAGE_ORDER SID TIMES CONTENT
20150825 1 4711 25.08.15 06:38:43 / body/home
4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938
20150825 3 4711 25.08.15 06:39:15 welcome, aufmacher, Home, 42303938
20150825 4 4711 25.08.15 06:39:20 home, aufmacher, Home, 42303938
20150825 5 4711 25.08.15 06:39:24 home, aufmacher, Home, 42303938
20150825 6 4711 25.08.15 06:39:32 home, aufmacher, Home, 42303938
20150825 7 4711 25.08.15 06:39:39 home/aufmacher/Home/42303938
20150825 8 4711 25.08.15 06:39:46 welcome, aufmacher, Home, 42303938
20150825 9 4711 25.08.15 06:39:49 home, aufmacher, Home, 42303938
4711 10 20150825 25.08.15 06:39:51 home, aufmacher, Home, 42303938
4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris
20150825 12 4711 25.08.15 06:42:36 / body/home
20150825 13 4711 25.08.15 07:06:09 / body/home
20150825 14 4711 25.08.15 07:06:36 reg/article/memo
I want as a result:
20150825 1 4711 25.08.15 06:38:43 / body/home
4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938
4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris
20150825 12 4711 25.08.15 06:42:36 / body/home
20150825 14 4711 25.08.15 07:06:36 reg/article/memo
Who knows a good way?
Thank you very much
It sounds like a simple solution group. You group by content and maybe a few other columns such as the day and sid. So, you want to show some value of inside this group. Several different aggregate functions to do this.
Not tested, because of lack of tabe create and insert scripts
select day, sid, content ,min(page_order) as page_order ,min(times) as times -- if the first page_order also has the first time ,min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time from yourTable group by day, sid, content
If Solomon is right, and several identical content may exist (the example data show that). Then we can use the Tabibitosan method to create the groups.
with step1 as (select t1.*, row_number() over (partition by day, sid, content order by page_order) rn from yourTable ) select day, sid, content , page_order - rn as group_number , min(page_order) as page_order , min(times) as times -- if the first page_order also has the first time , min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time from step1 group by day, sid, content, page_order - rn order by day, sid, content, group_number;
-
Calendar events hotmail disappeared days corresponding to the monthly calendar
My hotmail calendar displays more events that I posted in my monthly calendar display. They appear at the far left of the first day of each week in the monthly calendar. They appear correctly in all other views of the calendar. This just happened recently. What can I do about it?
Hello
I'm sorry, but we cannot help with hotmail problems in these forums in response to vista
Please repost your question in hotmail in the hotmail link below forums
http://windowslivehelp.com/product.aspx?ProductID=1
ForumsConsult with Microsoft Certified Solutions____________________________________________Welcome to Windows Live Solution Center -
How do the 3rd week (business day) of the month in a date range?
Hello
I'm trying to find the 3rd day of the work week of each month in a given range of dates. How is it possible in a SQL query? Thank you in advance.
Hello
Here's one way:
SELECT first_day + BOX
WHEN TO_CHAR (first_day, "DY") IN ("play", "Fri", "SAT")
THEN 4
WHEN TO_CHAR (first_day, "DY") ("SUN")
THEN 3
2 ELSE
END AS workday_3
DE)
SELECT ADD_MONTHS (first_month
, LEVEL - 1
) AS first_day
DE)
SELECT TO_DATE ('Sep 2013', 'My YYYY') AS first_month
, TO_DATE ('Jan 2014', 'Mon YYYY') AS last_month
OF the double
)
CONNECT BY LEVEL<= 1="" +="" months_between="" (last_month,="">=>
)
ORDER BY workday_3
;
In another thread,.
https://community.Oracle.com/thread/3513808
you said that you had problems using a WITH clause, so I used online views instead of CLAUSES.
With the above parameters, the result is:
WORKDAY_3
---------------
Wed 04-Sep-2013
Set of 3 October 2013
November 5, 2013 Mar
Wednesday, December 4, 2013
Fri January 3, 2014
-
Select SQL statement - See all the value of the range of month of entry
Hi all
I have a vision that is a union of other views
But the description of the view is as below
-current data in the viewdesc dashboard_monthly_view Name Null Type ------------------------------ ---- ------------ MONTHS VARCHAR2(17) NUM_DEPENDENT_IN_ASSESSMENT NUMBER NUM_REFERRED_AODTC NUMBER NUM_AT_DETERMINATION_HEARING NUMBER NUM_ACCEPTED NUMBER NUM_NOT_ACCEPTED NUMBER NUM_EXITED_SUCCESS NUMBER AVERAGE_DAY_TO_EXIST NUMBER NUM_EXITED_UNSUCCESS NUMBER AVERAGE_DAY_TO_EXIST_UNSUCCESS NUMBER COURT_NAME VARCHAR2(9)
-My select query isMONTHS NUM_DEPENDENT_IN_ASSESSMENT NUM_REFERRED_AODTC NUM_AT_DETERMINATION_HEARING NUM_ACCEPTED NUM_NOT_ACCEPTED NUM_EXITED_SUCCESS AVERAGE_DAY_TO_EXIST NUM_EXITED_UNSUCCESS AVERAGE_DAY_TO_EXIST_UNSUCCESS COURT_NAME ----------------- --------------------------- ---------------------- ---------------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ------------------------------ ---------- AUG 2012 1 0 0 0 0 0 0 0 0 AAA OCT 2012 8 1 3 1 1 1 44 1 4 AAA SEP 2012 2 0 2 2 0 0 0 0 0 AAA *UNDEFINED* 0 11 7 1 1 0 0 1 0 AAA NOV 2012 0 0 0 0 0 0 0 1 54 BBB OCT 2012 4 1 2 1 1 1 9 0 0 BBB SEP 2012 1 0 0 0 0 1 14 0 0 BBB *UNDEFINED* 0 5 4 1 0 0 0 1 0 BBB AUG 2012 1 0 0 0 0 0 0 0 0 COMBINED NOV 2012 0 0 0 0 0 0 0 1 54 COMBINED OCT 2012 12 2 5 2 2 2 26.5 1 4 COMBINED SEP 2012 3 0 2 2 0 1 14 0 0 COMBINED *UNDEFINED* 0 16 11 2 1 0 0 2 0 COMBINED 13 rows selected
- And the result isDEFINE startmonth = "Aug 2012"; DEFINE endmonth = "Nov 2012"; with all_months as ( select to_char(which_month, 'MON YYYY') month from (select add_months(to_date('&startmonth','MON YYYY'), rownum-1) which_month from all_objects where rownum <= months_between(to_date(NVL('&endmonth', '&startmonth'),'MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1)) order by which_month ) ) select nvl(months, '**ALL**') AS "MONTHS", TO_DATE(MONTHS, 'MON YYYY') AS MONTH_SORT , sum(num_dependent_in_assessment) AS num_dependent_in_assessment , sum(num_referred_aodtc) AS num_referred_aodtc , sum(num_at_determination_hearing) as num_at_determination_hearing , sum(num_accepted) AS num_accepted , sum (num_not_accepted) AS num_not_accepted , sum(num_exited_success) as num_exited_success , sum(average_day_to_exist) as average_day_to_exist , sum(num_exited_unsuccess) as num_exited_unsuccess , sum (average_day_to_exist_unsuccess) as average_day_to_exist_unsuccess from DASHBOARD_MONTHLY_VIEW right outer join all_months on DASHBOARD_MONTHLY_VIEW.months = all_months.month --where months in (select month from all_months) and upper(court_name) like 'AAA' group by (months) order by month_sort
-The requirement of results I have to produce isMONTHS MONTH_SORT NUM_DEPENDENT_IN_ASSESSMENT NUM_REFERRED_AODTC NUM_AT_DETERMINATION_HEARING NUM_ACCEPTED NUM_NOT_ACCEPTED NUM_EXITED_SUCCESS AVERAGE_DAY_TO_EXIST NUM_EXITED_UNSUCCESS AVERAGE_DAY_TO_EXIST_UNSUCCESS ----------------- ------------------------- --------------------------- ---------------------- ---------------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ------------------------------ AUG 2012 01/08/12 1 0 0 0 0 0 0 0 0 SEP 2012 01/09/12 2 0 2 2 0 0 0 0 0 OCT 2012 01/10/12 8 1 3 1 1 1 44 1 4 **ALL**
On the tota (* EVERYTHING *) l, I tried to use the rollup but he total average too, which is not correct. I think the reason because he cannot read the form that was used to calculate the column.MONTHS MONTH_SORT NUM_DEPENDENT_IN_ASSESSMENT NUM_REFERRED_AODTC NUM_AT_DETERMINATION_HEARING NUM_ACCEPTED NUM_NOT_ACCEPTED NUM_EXITED_SUCCESS AVERAGE_DAY_TO_EXIST NUM_EXITED_UNSUCCESS AVERAGE_DAY_TO_EXIST_UNSUCCESS ----------------- ------------------------- --------------------------- ---------------------- ---------------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ------------------------------ AUG 2012 01/08/12 1 0 0 0 0 0 0 0 0 SEP 2012 01/09/12 2 0 2 2 0 0 0 0 0 OCT 2012 01/10/12 8 1 3 1 1 1 44 1 4 NOV 2012 01/11/12 0 0 0 0 0 0 0 0 0 **ALL**
How can I fix this, should I create, select another below one, with the sum of each column and the average for the other columns.
Also, the business analyst want to show all the months between the start and end of the month.
I used the right outer join, but apparently does not produce the right result.
If anyone of you have any ideas, please advise.
We use Oracle 11 g, it is a select statement for an Oracle APEX report.
The APEX version is 4.0.2. I'm a junior developer of the APEX and I still have to learn a lot about SQL Oracle analytic function.
Thank you very much in advance.
AnnHi, Ann.
Ann586341 wrote:
... I created a table to contain a simplified version of this viewThank you. It is much easier to work with.
... My query is
DEFINE startmonth = "Aug 2012"; DEFINE endmonth = "Nov 2012"; with all_months as ( select to_char(which_month, 'MON YYYY') month from (select add_months(to_date('&startmonth','MON YYYY'), rownum-1) which_month from all_objects where rownum <= months_between(to_date(NVL('&endmonth', '&startmonth'),'MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1)) order by which_month ) ) , tbl_dashboard_active as ( select * from tbl_dashboard_monthly where months != '**UNDEFINED**' ) select tbl.months AS "MONTHS" --, TO_DATE(tbl.MONTHS, 'MON YYYY') AS MONTH_SORT , tbl.num_hearing , tbl.num_exited_success , tbl.avg_day_success_exist , tbl.num_exited_unsuccess , tbl.avg_day_unsuccess_exist from tbl_dashboard_active tbl right outer join all_months am on tbl.months = am.month and upper(tbl.court_name) like 'BBB' UNION ALL select 'ALL' AS "TOTAL" , SUM(tbl.num_hearing) , SUM(tbl.num_exited_success) , round(AVG(tbl.avg_day_success_exist),2) , SUM(tbl.num_exited_unsuccess) , round(AVG(tbl.avg_day_unsuccess_exist),2) --order by to_date(am.month,'MON YYYY') from tbl_dashboard_monthly tbl right outer join all_months am on tbl.months = am.month and upper(tbl.court_name) like 'BBB'
- And the result I got
MONTHS NUM_HEARING NUM_EXITED_SUCCESS AVG_DAY_SUCCESS_EXIST NUM_EXITED_UNSUCCESS AVG_DAY_UNSUCCESS_EXIST ----------------- ----------- ------------------ --------------------- -------------------- ----------------------- AUG 2012 1 0 0 0 0 OCT 2012 1 0 0 2 35 SEP 2012 1 0 0 0 0 ALL 3 0 0 2 11.67
I don't know why even I already filter all lines that the month is undefined, I still have a blank line in the result set.
This is the line for November. You do an outer join, in order to ensure that each value of am.month is displayed, even if it does not match what anyone in tbl. When it does not match anything, then all the columns tbl is supposed to provide will be NULL. You decide to view tbl. months, which is one of the following columns will be NULL. You should display mod. monmth instead.
But if I run for handset Court, I don't see this problem. The reason is that the Court combined have given for all four months?
When you say "on behalf of the combined Court", do you mean the unconditional "upper (tbl.court_name) as"BBB "?
If Yes, that would explain it.Also is it possible to list all the months between the start and end month assuring the user even if the statistics are 0.
Once again, in the case of lines that are present, even if they do not have the status of outer join, all of these columns will be NULL. Use NVL to map these nulls to 0.
and how to sort the month
GROUP OF two expressions, which depend on each other: one for sorting and the other for display.
For the sort expression, you can use months as a DATE. (It seems that you have tried this, but commented on the ORDER BY clause in your query is before the FROM clause.) The ORDER BY clause is always at the end of the query, after the FROM clause.)
Another expression of sorting is the number you used to generate the first month. That's what I used below.Here's a way to get the results you requested:
WITH got_months AS ( SELECT TO_DATE ('&startmonth', 'Mon YYYY') AS startmonth_dt , TO_DATE ( NVL ( '&endmonth' , '&startmonth' ) , 'Mon YYYY' ) AS endmonth_dt FROM dual ) , all_months AS ( SELECT rownum AS month_num , TO_CHAR ( ADD_MONTHS ( m.startmonth_dt , ROWNUM - 1 ) , 'MON YYYY' ) AS months FROM got_months m CROSS JOIN all_objects WHERE ROWNUM <= 1 + MONTHS_BETWEEN ( m.endmonth_dt , m.startmonth_dt ) ) SELECT NVL ( am.months , 'All' ) AS months , SUM (NVL (tbl.num_hearing, 0)) AS num_hearing , SUM (NVL (tbl.num_exited_success, 0)) AS num_exited_success , AVG (NVL (tbl.avg_day_success_exist, 0)) AS avg_day_success_exist , SUM (NVL (tbl.num_exited_unsuccess, 0)) AS num_exited_unsuccess , AVG (NVL (tbl.avg_day_unsuccess_exist, 0)) AS avg_day_unsuccess_exist FROM all_months am LEFT OUTER JOIN tbl_dashboard_monthly tbl ON am.months = tbl.months AND UPPER (tbl.court_name) = 'BBB' GROUP BY GROUPING SETS ( (am.month_num, am.months) , () ) ORDER BY am.month_num ;
Again, I used two GROUP BY expressions: one for sorting, the other for display. These depend on each other, that is, given one, you could derive from each other, and it is not sensible to dependent ROLLUP GROUP BY expressions like that, so I used GROUPING SETS ROLLUP instead, so it would be only 1 rank of great aggregate (in other words, 'all').
Output:
` AVG_ AVG_ NUM_ DAY_ NUM_ DAY_ NUM_ EXITED_ SUCCESS EXITED_ UNSUCCESS MONTHS HEARING SUCCESS _EXIST UNSUCCESS _EXIST --------- ------- ------- ---------- --------- ---------- AUG 2012 1 0 0 0 0 SEP 2012 1 0 0 0 0 OCT 2012 1 0 0 2 35 NOV 2012 0 0 0 0 0 All 3 0 0 2 8.75
-
turnover of 18 weeks from the week of the current month number
Hello
I have a requirement as described below.
Time table name:
Columns: year, month of exercise and exercise week
table above has the join with the sales table and contains data on sales according to the week. so less granularity of data at the level of the week.
We have a report that contains columns exercise, actual sales and forcast sales. our requirement is to filter the data with the following criteria.
Filter for the current month
Fiscal week Jan between 1-18 of the current year
Fiscal week Feb between 5-23 of the current year
Week fiscal March between 9-27 to the current year
.
.
.
.
Fiscal week November between 44 the week of the current year and week 10 of next year
December
with above requirement therefore filter the data bearing 18 weeks from the week of the current month number
I tried with timestampadd (interval, sql_tsi_week, week), but it does not work as I expacting. Please provide the code/logic to do so.
Appreciate your help.
Thank you
Jay.Jay wrote:
I need to get the results of 18 weeks of turning to anypoint starting with the week number of the 1st of every month at 18 weeks. read my question again once and you will be able to understand.It kind you of lack the point to be honest. It is very difficult to answer specific questions without the required information. To answer a question like this we need a minimum of:
1. oracle version
2. examples of data (CREATE TABLE / INSERT statements)
3. expected results
4. explanation of the business rules.Alternatively, you can read the link in my original reply.
Please provide the information requested and someone can help.
-
How to get the name of the month of week number
Hi gurus,
I have week a year numbers.
I want to get the name of the month using the number of the week.
Is it possible to do this by using SQL.
Help, please.
Thank you
DominicSQL> var week number SQL> var year number SQL> SQL> begin 2 :year := 2007; 3 :week := 30; 4 end; 5 / PL/SQL procedure successfully completed. SQL> select to_char(trunc(to_date(:year,'yyyy'),'iyyy') + :week * 7, 'Month') month from dual 2 / MONTH --------- July SQL>
Maybe you are looking for
-
Download firefox if I download bitdefender 2014
Just download bitdefender 2014 for 2 years from http://www.anti-virus4u.com/ I read that bitdefender support firefox I have internet explore how can I download firefox? what I do when I update my bitdefender BitDefender 2015 can I still use my old fi
-
Missing file... HP product Assistant.msi
Hello I hope someone can help me! I have a HP G60-214EM HPG60 laptop... Since a few days ago recovery disks, a popup HP assistant continously product comes up saying ' the featureyou are to use is on a CD-ROM or another removable disk that is not ava
-
I'm trying to print address application envelope Word but direction address not correct. Followed printer manufact. instructions. Printer manu is not their fault.
-
Hi all My fiancee and I just bought an Acer A210 each and we noticed that 4.1 android is installed as the norm rather than the latest version 4.2. Our legs will get the update from 4.1 to 4.2? I saw you can download versions 4.2 ROM flashing the tab,
-
Realtek rtl8188su wireless lan update 802.11n usb 2.0 network adapter
Realtek rtl8188su wireless lan update 802.11n usb 2.0 network adapter. What are the problems he says. is it necessary?