Query (no, day, Date)
Hello
This query shows how many days
Select level as dow, to_char (trunc (: P_date, 'day') + level - 1, 'day', 'NLS_DATE_LANGUAGE = ARABIC') as day, TO_DATE (: P_date, "dd-mm-rrrr") + T2D rownum-1 of dual connect by level < = 7;
I want to change the query starting with
7 Saturday date Saturday
1 Sunday Sunday date
2 Monday Monday date
3 Tuesday
and so on.
Amatu Allah.
Hello
I see it; you want to spend 2 parameters DATE (start date and an end date) and generate a result set contains a line for each day in this range.
In response #5, Kendeeny showed how to generate the 7 dates starting at a given date. You can change that to generate however many you need, based on 2 parameters, as follows:
WITH the settings THAT
(
SELECT TO_DATE (December 19, 2015 ", 'DD-MM-YYYY') AS first_date
, TO_DATE (27 December 2015 ", 'DD-MM-YYYY') AS last_date
OF the double
)
SELECT the LEVEL - 1 AS day_name + first_date
OF parameters
CONNECT BY LEVEL<= 1="" +="" last_date="" -="">=>
;
It produces just the DATEs:
DAY_NAME
----------
19/12/2015
20/12/2015
21/12/2015
22/12/2015
23/12/2015
24/12/2015
25/12/2015
26/12/2015
27/12/2015
Now, we must add the other 2 columns we want.
DAY_ID DAY_DATE DAY_NAME
---------- --------- ----------
7 Saturday, December 19, 2015
1 Sunday, December 20, 2015
2 Monday, December 21, 2015
3 Tuesday, December 22, 2015
4 Wednesday, December 23, 2015
5 Thursday, December 24, 2015
6 Friday, December 25, 2015
7 Saturday, December 26, 2015
1 Sunday, December 27, 2015
The day_date column is easy using TO_CHAR.
Day_id is more complicated. Here's a way to do it, using the TRUNC:
WITH the settings THAT
(
SELECT TO_DATE (December 19, 2015 ", 'DD-MM-YYYY') AS first_date
, TO_DATE (27 December 2015 ", 'DD-MM-YYYY') AS last_date
OF the double
)
got_d AS
(
SELECT the LEVEL - 1 AS d + first_date
OF parameters
CONNECT BY LEVEL<= 1="" +="" last_date="" -="">=>
)
SELECT 2 + d - TRUNC (d + 1, 'IW') AS day_id
TO_CHAR (d
, 'Day '.
-, ' NLS_DATE_LANGUAGE = ARABIC '.
) AS day_date
, TO_CHAR (d, 'dd-mm-yyyy') AS day_name
OF got_d
ORDER BY d
;
TRUNC (d, 'IW') returns later Monday less than or equal to d. This is a handy feature, and it is independent of the settings NLS_DATE_LANGUAGE and NLS_TERRITORY.
d - TRUNC (d, 'IW') maps the days of the week to consecutive integers, but it assigns the lowest value on Monday. We want Sunday to have the lowest number, so I used
d - (TRUNC (d + 1, 'IW') instead.) The 'magic number' 1 reflects the fact that Monday is a day after the Sunday. It returns a number in the range from-1 to 5, but we want numbers in the range 1 to 7, that is exactly 2 more, so add 2.
Tags: Database
Similar Questions
-
Query to group dates by days of week
Hello
I have a table that contains the following format:
Create table testtable(dates date, day_identifier number);
The data in the day_identifier column contains day dates of the corresponding columns of equivalent week, i.e.
to_char(dates, 'd')
The table contains a suite of sample data:
Dates Day_identifier October 1, 2013 3 October 2, 2013 4 4 October 2013 6 October 6, 2013 1 8 October 2013 3 October 9, 2013 4 October 11, 2013 6 October 18, 2013 6 October 21, 2013 2 October 23, 2013 4 I am looking for a query that will consolidate the data above, based on the data in the column day_identifier in the following format:
October 1, 2013 1346 11 October 2013
18 October 2013 October 23, 2013 246
The above so well developed data for example
all dates between October 1, 2013 and October 11, 2013 and the day of the week value in 1,3,4,6
and
all dates between October 18, 2013 and October 23, 2013 and having the day of the week in 2,4,6 value
will give me the result set from the table above.
Please help me to solve the issue.
Thank you.
Like this? (The results of the previous example has not changed)
with
flights only
(select 1 flight_no, to_date('01-10-2013','dd-mm-yyyy') flight_date, 3 day_identifier union double all the)
Select 1, to_date (March 10, 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (August 10, 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (October 10, 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (October 15, 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (17 October 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (22 October 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (24 October 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (29 October 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (31 October 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (11 may 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (11 July 2013 ', 'dd-mm-yyyy'), 5 Union double all the
-select 1, to_date (December 11, 2013 ',' dd-mm-yyyy '), 3 all the double union
Select 1, to_date (14 November 2013 ', 'dd-mm-yyyy'), 5 Union double all the
-select 1, to_date (November 19, 2013 ',' dd-mm-yyyy '), 3 all the double union
Select 1, to_date (November 21, 2013 ', 'dd-mm-yyyy'), 5 Union double all the
-select 1, to_date (November 26, 2013 ',' dd-mm-yyyy '), 3 all the double union
Select 1, to_date (28 November 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (March 12, 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (May 12, 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (12 October 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (12 December 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (17 December 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (19 December 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (24 December 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (December 26, 2013 ', 'dd-mm-yyyy'), 5 Union double all the
Select 1, to_date (31 December 2013 ', 'dd-mm-yyyy'), 3 union double all the
Select 1, to_date (February 1, 2014 "," dd-mm-yyyy '), 5 Union double all the
Select 1, to_date (July 1, 2014 "," dd-mm-yyyy '), 3 Union double all the
Select 1, to_date (September 1, 2014 "," dd-mm-yyyy '), 5 Union double all the
Select 1, to_date (January 14, 2014 "," dd-mm-yyyy '), 3 Union double all the
Select 1, to_date (January 16, 2014 "," dd-mm-yyyy '), 5 Union double all the
Select 1, to_date (January 21, 2014 "," dd-mm-yyyy '), 3 Union double all the
Select 1, to_date (January 23, 2014 "," dd-mm-yyyy '), 5 Union double all the
Select 1, to_date (28 January 2014 "," dd-mm-yyyy '), 3 Union double all the
Select 1, to_date (January 30, 2014 "," dd-mm-yyyy'), 5 double
),
all_identifiers as / * collection presents all the day_identifier * /.
(select flight_no,
min (from_date) from_date,
Max (till_date) till_date,
listagg(day_identifier,'') within the Group (order by day_identifier) day_identifiers
from (select flight_no,
min (flight_date) from_date,
Max (flight_date) till_date,
day_identifier
flights
Flight_no group, day_identifier
)
Flight_no group
),
generated_rows as / * generate all the resulting flight_date of day_identifier collected * /.
(select flight_no,
flight_date,
day_identifier
from (select flight_no,
level - 1 flight_date, + from_date
case when instr (day_identifiers, to_char (tier - 1, + from_date '))! = 0
then to_number (to_char (tier - 1, + from_date '))
end day_identifier
of all_identifiers
connect by level<= till_date="" -="" from_date="" +="">=>
and prior flight_no = flight_no
and prior sys_guid() is not null
)
where day_identifier is not null
),
matched_rows as / * flights against generated lines correspondence reveals partially cancelled flights * /.
(select g.flight_no,
g.flight_date generated_date,
g.day_identifier,
f.day_identifier flights_day_identifier / * null if flight cancelled * /.
of generated_rows g
left outer join
F flights
on g.flight_no = f.flight_no
and g.flight_date = f.flight_date
and g.day_identifier = f.day_identifier
),
grouped_rows as / * grouping of lines before the final response * /.
(select flight_no,
generated_date,
day_identifier,
flights_day_identifier,
-case when count (day_identifier) on (partition flight_no, day_identifier
order of generated_date
lines between unbounded preceding and following unlimited
) =
Count (flights_day_identifier) more (partition flight_no, day_identifier
order of generated_date
lines between unbounded preceding and following unlimited
)
Press 'Finish' / * count_of_all = count_of_not_null * /.
otherwise "incomplete".
end day_identifier_type
ROW_NUMBER() (flight_no, day_identifier, generated_date order)-
ROW_NUMBER() over grp (partition flight_no, day_identifier, flights_day_identifier order of generated_date) / * tabibitosan * /.
of matched_rows
)
Select flight_no,
TO_CHAR (min (from_date), 'dd-mon-yyyy') from_date,.
TO_CHAR (Max (till_date), 'dd-mon-yyyy') till_date,.
listagg(day_identifier,'') within the Group (order by day_identifier) day_identifiers
from (select flight_no,
min (generated_date) from_date,
Max (generated_date) till_date,
day_identifier
of grouped_rows
where day_identifier_type = 'Finish '.
Flight_no group, day_identifier
)
Flight_no group
Union of all the
Select distinct
flight_no,
TO_CHAR (FIRST_VALUE (generated_date) more (partition flight_no, grp)
order of generated_date
),
"Mon-dd-yyyy".
) from_date,.
TO_CHAR (FIRST_VALUE (generated_date) more (partition flight_no, grp)
generated_date desc order
),
"Mon-dd-yyyy".
) till_date,.
TO_CHAR (day_identifier) day_identifiers
of grouped_rows
where day_identifier_type = "incomplete".
and flights_day_identifier is not null
order of flight_no, day_identifiers, from_date
FLIGHT_NO FROM_DATE TILL_DATE DAY_IDENTIFIERS 1 October 1, 2013 November 5, 2013 3 1 December 3, 2013 January 28, 2014 3 1 October 3, 2013 January 30, 2014 5 Concerning
Etbin
-
Oracle query to generate date and calculate fees
Hi, please help me to create a query to get the end result of both tables as below
CREATE TABLE detention_charge_slot (slot_no NUMBER(5), from_days NUMBER(10), to_days NUMBER(10), charge_amount NUMBER(10,2)); INSERT INTO detention_charge_slot VALUES (1,1,4,0); INSERT INTO detention_charge_slot VALUES (2,5,9,10); INSERT INTO detention_charge_slot VALUES (3,10,14,20); INSERT INTO detention_charge_slot VALUES (4,15,999,25); CREATE TABLE detention_invoice (invoice_no NUMBER(10), invoice_dt DATE, delivery_dt DATE); INSERT INTO detention_invoice VALUES(1,'10-JAN-2015','25-JAN-2015');
Where expected result 1 = Invoice_no:
Start_date End_date Days Charge_Amount JANUARY 10, 2015 JANUARY 13, 2015 4 0 JANUARY 14, 2015 18 JANUARY 2015 5 10 19 JANUARY 2015 JANUARY 23, 2015 5 20 JANUARY 24, 2015 25 JANUARY 2015 2 25 If you expect more than one line in DETENTION_INVOICE, use the following query
WITH DATES
AS
(SELECT DI. INVOICE_DT + FROM_DAYS - 1 START_DATE,
LEAST (DI. INVOICE_DT + TO_DAYS - 1, DELIVERY_DT) END_DATE.
CHARGE_AMOUNT
OF DCS, DETENTION_INVOICE DI DETENTION_CHARGE_SLOT
where di.invoice_no = 1)
SELECT start_date, end_date - + 1 days START_DATE, end_date, charge_amount
OF DATES
-
Create the query by combining data from DBSS_Data_Model and HostModel
Hello
I am trying to create a dashboard with the host server list and instances of SQL Server running on the host.
And I am interested in creating a query by combining data model of data in SQL Server (DBSS_Data_Model) and the host (Hosts) data model, say: which connects DBSS_SQL_Server_Host and host.
I wonder if there is way to do it?
Thank you
Mark
Something like this function should work:
def physicalHost = nullqueryStatement = server.QueryService.createStatement("(Host where name = '$hostName')")result = server.QueryService.executeStatement(queryStatement)objs=result.getTopologyObjects() if (objs != null && objs.size() > 0) { physicalHost = objs.get(0)}return physicalHost
When the input parameter "hostName" is DBSS_SQL_Server_Host.physical_host_name
Kind regards
Brian Wheeldon
-
query to display data in table with several detail table
Hi all
I have a few cases with a table header that have more than 3 table of detail, and I have to generate the query to show all the data horizontally.
tblHdr have column A (PK)
tblDtl1 have column A (FK), B (PK)
tblDtl2 have column A (FK), C (PK)
tblDtl3 have column A (FK), D (PK)
and I need a query to display data like this:
A B1 C3 D1 A B2 C4 D2 A C5 D3 A C6 all the Details of the table should display data based on the relationship of tblHdr (A).
tblDtl1 have only 2 rows of data for the FK A
tblDtl2 just for FK 4 lines of data
tblDtl3 only 3 lines of data for the FK A
Another example:
A B1 C1 D1 A B2 C2 A B3
tblDtl1 only 3 lines of data for the FK A
tblDtl2 have only 2 rows of data for the FK A
tblDtl3 have only 1 rows of data for the FK A
Please shed some light. for the record, I'll use this query in ADF, so I'll put using PLSQL in second priority. I prefer to do it in the SQL query.
Thank you
Here are 3 ways. First test of data:
drop table ta purge; create table ta as SELECT 'A' AS A FROM dual union all select 'B' from dual; drop table tb purge; create table tb as SELECT 'A' AS A, 'B1' AS B FROM dual UNION ALL SELECT 'A', 'B2' FROM dual ; drop table tc purge; create table tc as SELECT 'A' AS A, 'C1' AS C FROM dual UNION ALL SELECT 'A', 'C2' FROM dual UNION ALL SELECT 'A', 'C3' FROM dual UNION ALL SELECT 'A', 'C4' FROM dual ; drop table td purge; create table td as SELECT 'A' AS A, 'D1' AS D FROM dual UNION ALL SELECT 'A', 'D2' FROM dual UNION ALL SELECT 'A', 'D3' FROM dual;
Now 3 solutions: full join, group by and pivot:
with b as ( select a, b, row_number() over(partition by a order by b) rn from tb ) , c as ( select a, c, row_number() over(partition by a order by c) rn from tc ) , d as ( select a, d, row_number() over(partition by a order by d) rn from td ) select a, b, c, d from ta left join b using(a) full join c using(a, rn) full join d using(a, rn) order by a, rn; select a, max(b) b, max(c) c, max(d) d from ( select a, null b, null c, null d, 1 rn from ta union all select a, b, null, null, row_number() over(partition by a order by b) rn from tb union all select a, null, c, null, row_number() over(partition by a order by c) rn from tc union all select a, null, null, d, row_number() over(partition by a order by d) rn from td ) group by a, rn order by a, rn; select A,B,C,D from ( select 'A' tab, a, null val, 1 rn from ta union all select 'B' tab, a, b, row_number() over(partition by a order by b) rn from tb union all select 'C' tab, a, c, row_number() over(partition by a order by c) rn from tc union all select 'D' tab, a, d, row_number() over(partition by a order by d) rn from td ) pivot(max(val) for tab in('B' B, 'C' C, 'D' D)) order by a, rn;
A B C D A B1 C1 D1 A B2 C2 D2 A C3 D3 A C4 B Personally, I would prefer to view the data by using a 'join the union', in order to avoid the impression that the different detail records are related somehow.
select ta.a, b, c, d from tb full join tc on 1=0 full join td on 1=0 right join ta on ta.a in (tb.a, tc.a, td.a);
A B C D A B1 A B2 A C1 A C2 A C3 A C4 A D1 A D2 A D3 B -
Output query based on date - Oracle 8i
I'm writing a very simple query for output data based on date ranges, but I continue to encounter an error.
When I make this statement:
Select * from my.table
where startdate > ' 2008-01-01'
I get this error:
[ODBC] [Ora] ORA-01861: literal does not match the format string
When I format the select statement in this way:
Select * from my.table
where startdate > #2008-01-01 #.
I get this error:
[ODBC] [Ora] ORA-00932: inconsistent data types: expected DATE got the NUMBER
Currently using CF8, and what I believe is Oracle 8i. I tried these data in many other ways of formatting, but can not make it work. I know that when I query the database using access, he has no problem returns results with the date SQL formatted as # #01 / 01 / 2008You can use the Oracle to_date() function to convert your string to a date/time object:
Select * from my.table
where startdate > to_date ('2008-01-01', ' YYYY-MM-DD "")Otherwise, because you are using an ODBC for Oracle connection, you can try using the function CreateODBCDate() in ColdFusion:
Select * from my.table
where startdate > #CreateODBCDate("2008-01-01") #.Or, as has already been suggested, use cfqueryparam with the proper CFSQLType, such as CF_SQL_TIMESTAMP instead of CF_SQL_INTEGER as you try to do.
You can not use a date value 'string' against a date/time column in a query Oracle, as he proceed to an implicit type conversion.
Phil
-
How can I create a query with the data control to the web service?
I need to create a query with the order of web service data, WSDL, it is query operation, there is a message of parameter with possible query criteria and a return message contains the results. I googled but can't find anything on the query with the web service. I can't find a criterion "named" to the data control of web service as normal data control. Blog of Shay, I saw the topics on the update with the data of web service command. How can I create a query with the data control to the web service? Thank you.Hello
This might help
* 054. Search form using control data WS ADF and complex of entry types *.
http://www.Oracle.com/technetwork/developer-tools/ADF/learnmore/index-101235.html
-
Query to extract data from source DB driver using process mapping pre...
Hi all
I have a source for the query to retrieve the data from the source database. Looking for suggestion what could be the best approach to extract data from the source database.using owb 11 GR 1 material.
I'm in printing, create the process of mapping driver prerequisite for aid to perform immediate with Create table T1 as a sql query. Petition to the sides of the Insert into T1 Select * from Source_Table in the different database.
Certainly, need to create Db users in the Source database, to get privileges to read the data of source_database.
Is - this good aproach to or of any other alternative to achieve this.
Means, create the table in the transit area (desired area, where I am) and using driver mapping process before you run the select query to retrieve data from a data source.
Would apreciate your previous answer.
Thank you
MAKYou can mark Correct or useful if it solves your purpose.
-
How to write a query for the data exchange between two columns?
How to write a query for the data exchange between two columns?
I tried a request, does NOT work.
Thank you.update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
Published by: user533361 on October 23, 2009 14:04Just plain and simple:
update tmp t1 set t1.m1=t1.m2, t1.m2=t1.m1 /
SY.
-
SQL Query to extract data between days and hours
Hi friends,
I need, it's for a report.
Description of the requirement:
Need of data in a table located in an OPEN State for more than 30 minutes
Well, this requirement can be obtained from
Select * from xyz where status = 'OPEN' and last_update_date < = sysdate---30 (30/1440) minutes and it is a parameter
the query above will search all data that are in the OPEN State beginning to sysdate - (30/1440). So I want to change the query to restrict the data, by adding another parameter as DAY
for example if I give 10 day, it should recover all the data only within 10 days and sysdate-30 minutes.
We use the last_update_date column to restrict the day.
If I do not give any date for entry must retrieve all records of sysdate-30 minutes.
If I don't give minutes that he must retrieve all the records in the OPEN State.
is the question clear enough? my English is bad.
Please suggest me a query...
Thank you and best regards,
Arun Thomas T
Hello
Select * from xyz where status = 'OPEN' and
last_update_date between nvl (sysdate -: days, last_update_date) and nvl2 (: days, last_update_date, nvl (sysdate -: minutes/1440, last_update_date));
that should be:
If the days parameter is entered then start - days of sysdate and end up last_update_date
If days is not entered then boot from the begingin and put end to:
1 sysdate -: minutes/1440 if minutes are entered
2. up to the last_update_date if the minutes are not entered
-
Query to find data on holidays
Hi, I have a table for special leave, which looks like this:
PROFILE_DAY VAR_DATE REGULAR_HOLIDAY 01/01/2013 H_WEEK_THURSDAY 28/03/2013 H_WEEK_FRIDAY 29/03/2013 REGULAR_HOLIDAY 24/12/2013 REGULAR_HOLIDAY 25/12/2013 REGULAR_HOLIDAY 31/12/2013 And another table (LOAD_PROFILE_TEST) that contains the values of (TIME_EQ) 0-24 LOAD_PROF1 intervals 0.25 for (PROFILE_DAY) MONDAY to SUNDAY including REGULAR_HOLIDAY, H_WEEK_THURSDAY and H_WEEK_FRIDAY. Overall, this table contains 970 records (97 separate 0-24 with interval of 0.25 per PROFILE_DAY, with 10 PROFILE_DAY).
TIME_EQ PROFILE_DAY LOAD_PROF1 LOAD_PROF2 0 REGULAR_HOLIDAY 11.47 0.25 REGULAR_HOLIDAY 11.27 0.5 REGULAR_HOLIDAY 11.3 0.75 REGULAR_HOLIDAY 11.08 0 MONDAY 11.27 0.25 MONDAY 11.33 0.5 MONDAY 11.18 Now I have this request to update the value of LOAD_PROF2 in the table every time that the V_DATE_OUT and V_DATE_IN parameters is entered:
UPDATE LOAD_PROFILE_TEST
SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFF
WHERE UPPER (PROFILE_DAY) IN (select UPPER (to_char (: V_DATE_OUT + (level 1), "fmDAY")))
of the double
connect by level < =: V_DATE_IN -: + 1 V_DATE_OUT
);
where: LOAD_DIFF is some predetermined value.
This query works fine if I'm trying to update regular days from MONDAY to SUNDAY. What I would do is to determine if the two dates of setting, V_DATE_OUT & V_DATE_IN would fall under none of the holidays on the first table LOAD_PROFILE_TEST, and then update the lines only. For example, V_DATE_OUT = 12/02/2013, Monday and V_DATE_IN = 06/12/2013, Friday. The query above would update the values of the LOAD_PROF2 for PROFILE_DAY - MONDAY to FRIDAY, corresponding to the dates of 02/12/2013 and on 06/12/2013. If, however, V_DATE_OUT = 23/12/2013, Monday and V_DATE_IN = 27/12/2013, Friday, it should update the lines corresponding to PROFILE_DAY - MONDAY 23/12/2013, THURSDAY for 26/12/2013, FRIDAY for 12 27, 2013, and REGULAR_HOLIDAY for the dates of 12 24, 2013 and 25/12/2013 since these two appear in the first table (table of holidays). This scenario works the same way when V_DATE_OUT and/or V_DATE_IN enter the dates of 28/03/2013 and 29/03/2013. All other dates not included in the table for special leave will be treated according to the day they fall on (from Monday to Sunday). I hope my point is clear. Thank you in advance.
arms777 wrote:
I have already given a test for the table,
Frank pleased to display:
"examples of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from this data."
I do not see the second statement in the create table and insert statements. Do you expect to write us your data ourselfs?
However I'll try it from scratch
merge into LOAD_PROFILE_TEST t
a_l'_aide_de)
Select distinct
Decode (var_date, null, theday, profile_day) profile_day
BeO
Select
SUPERIOR (to_char (: V_DATE_OUT + (level 1), 'fmDAY')) theday
,: V_DATE_OUT + subsist (level 1)
of the double
connect by level<= :v_date_in="" -="" :v_date_out ="" +="">=>
)
REG_HOLIDAYS
where
subsist = var_date (+)) g
on (UPPER (t.PROFILE_DAY) = g.profile_day
)
When matched then update
SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFFPost edited by: chris227
Fixed: added update -
Page reports there are two 2 day points of selector (a datefrom and dateto a) as well as a text field with AutoComplete element
When the page load query is called
SELECT
"COL1",.
"COL2",.
"COL3",.
the "table".
WHERE MYDATES BETWEEN: DATEFROM AND: DATETO
Which returns no records as no dates have been set.
How can I modify this search in the clause WHERE on the date element is called only when the dates are chosen, and by default, all the records are displayed.
The other related issue is when I chose a from and to date and research when I return in the view page of report after consulting other pages in the application of the apex, the form fields are always met, how can I delete the session down for these fields when the user leaves the page?
I hope that all makes sense?To_date('01.01.2100', 'dd.mm.yyyy')
will give erroneous results on 02.01.2100 :D
A solution (perhaps there's a cleaner...):
WHERE ((:DATEFROM IS NOT NULL AND mydates >= :DATEFROM) OR :DATEFROM IS NULL) AND ((:DATETO IS NOT NULL AND mydates <= :DATETO) OR :DATETO IS NULL)
You can change the message "No data found" by changing the attribute of report "when no. found data Message."
EDIT: And for the 2nd question, Alex is right, but also be aware that Firefox retains the values of form element when the page refreshes, you must change the Security page 'Form Auto Complete' to 'Disabled' attribute if you do not want to keep the form element values.
Published by: Yann39 on June 27, 2012 06:30
-
SQL query to group data by Code and dates
Hello
I have the following table structure
col1 col2 col3
January 21, 2012 tested Code1
January 20, 2012 tested Code1
June 1, 2012 tested Code1
June 1, 2012 tested Code2
code 3 tested June 4, 2012
so now
The output should be something like
code week1 week semaine2 3 semaine4 week5 until the last 14 weeks from the date that we run
code 1 1 0 0 0 0
Code2 1 0 0 0 0
code 3 0 1 0 0 0
where 1, 0 is in fact the charges and no sum and the week in this case perhaps should since we are in the second week, he should be
code... .week3 may semaine4 peut week1 jun week2june
Was looking for suggestions on how to achieve this.
I guess that this would require some kind of a pivot query?
Thank you
SunHello
Here's how you can make this pivot in Oracle 10.2. (In fact, it will work in Oracle 9.1 or higher.)
WITH got_week_num AS ( SELECT error_code, date_logged , 1 + FLOOR ( ( TO_DATE (:end_dt_txt, 'DD-Mon-YYYY') - date_logged) / 7 ) AS week_num FROM data_analysis WHERE date_logged >= TO_DATE (:start_dt_txt, 'DD-Mon-YYYY') AND date_logged < TO_DATE (:end_dt_txt, 'DD-Mon-YYYY') + 1 ) , all_weeks AS ( SELECT LEVEL AS week_num , TO_CHAR ( 1 + TO_DATE (:end_dt_txt, 'DD-Mon-YYYY') - (7 * LEVEL) , 'fmDD-Mon-YYYY' ) AS heading FROM dual CONNECT BY LEVEL <= 1 + FLOOR ( ( TO_DATE (:end_dt_txt, 'DD-Mon-YYYY') - TO_DATE (:start_dt_txt, 'DD-Mon-YYYY') ) / 7 ) ) SELECT NULL AS error_code , MIN (CASE WHEN week_num = 1 THEN heading END) AS week_1 , MIN (CASE WHEN week_num = 2 THEN heading END) AS week_2 -- ... , MIN (CASE WHEN week_num = 5 THEN heading END) AS week_5 FROM all_weeks -- UNION ALL -- SELECT error_code , TO_CHAR (COUNT (CASE WHEN week_num = 1 THEN 1 END)) AS week_1 , TO_CHAR (COUNT (CASE WHEN week_num = 2 THEN 1 END)) AS week_2 -- ... , TO_CHAR (COUNT (CASE WHEN week_num = 5 THEN 1 END)) AS week_5 FROM got_week_num GROUP BY error_code -- ORDER BY error_code NULLS FIRST ;
Output:
ERROR_CODE WEEK_1 WEEK_2 WEEK_5 ---------- ----------- ----------- ----------- 4-Jun-2012 28-May-2012 7-May-2012 a 3 0 0 b 0 2 1 c 0 0 1
Once more, the number of columns, such as aliases, is hard-coded in the query.
If you want the number of columns, or their aliases depends on the data in the table, then you need dynamic SQL. See {message identifier: = 3527823}Did you ever what defined a "week" is in this query?
The query above makes week_1 end to the given date (: end_dt_txt). The first week (in other words, an ioncluding: start_dt_txt) may have less than 7 days.
If you want all the weeks to start Monday (in which case, the first and the last few weeks may have less than 7 days) see stew solution, using TRUNC (date_logged, 'IW'). -
need help with query can find data back please help.
Hi guys I have a table such as
and I have a data as suchCREATE TABLE "FGL" ( "FGL_GRNT_CODE" VARCHAR2(60), "FGL_FUND_CODE" VARCHAR2(60), "FGL_ACCT_CODE" VARCHAR2(60), "FGL_ORGN_CODE" VARCHAR2(60), "FGL_PROG_CODE" VARCHAR2(60), "FGL_GRNT_YEAR" VARCHAR2(60), "FGL_PERIOD" VARCHAR2(60), "FGL_BUDGET" VARCHAR2(60) )
I need bascially to get the total of the budget column. However this is not as simple as it sounds good (at least not for the me.) totals carried forward to the new period. you will notice that you have a period column. Basically, what im is thatInsert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');
fgl_grant_year 10 1 period = account 7600 its $100 and $100 for the period 2, you see $ 100 more, it wants to not be added to this is the door on the balance. that is $100.
So im trying to write a query that basically does the following.
IM considering a period for the sake of this example let period 1 I get anything else. I find that the greates contributes dumpster year the amount for the period 14 (which corresponds to the total of the previous year) and add it to the amount of the current year. in this case period 1 grnt_year 11
the expected result is therefore $700
do not forget that I am not given a just a period of the year.240055 240055 7240 4730 02 10 14 200 240055 240055 7600 4730 02 10 14 100 240055 240055 7600 4730 02 11 1 400
any help you guys can give would be immensely appreciated. I tried to get this to work for more than 3 days now.
Finally broke down and put together this post
Published by: mlov83 on Sep 14, 2011 20:48Hello
Thanks for posting the CREATE TABLE and INSERT statemnts; It is very useful.
I'm not sure that understand your needs.
The correct output will be just one line:TOTAL_BUDGET ------------ 700
or will it be 3 ranks that you posted? I guess you want just line after line.
Do you mean that you are given a period (for example, 1).
First you have to find the largest gfl_grnt_year which is related to this period (in this case, 11).
Then you need to add fgl_budget lines that have to be
(1) the specific period and the largest fgl_grnt_year, or
(2) perriod = 14 and the previous fgl_grnt_year (in this case, 10).
Is this fair?If so, here's a way to do it:
WITH got_greatest_year AS ( SELECT fgl.* -- or whatever columns are needed , MAX ( CASE WHEN fgl_period = :given_period THEN fgl_grnt_year END ) OVER () AS greatest_year FROM fgl ) SELECT SUM (fgl_budget) AS total_budget -- or SELECT * FROM got_greatest_year WHERE ( fgl_grnt_year = greatest_year AND fgl_period = :given_period ) OR ( fgl_grnt_year = greatest_year - 1 AND fgl_period = 14 ) ;
If you want the 3 lines you have posted, then change the main SELECT clause to ' SELECT * ' (or, instead of *, youcan the columns you want to see the list).
-
I have a table with a column created_date . The data type is DATE.
When I query this table for a date range I still don't get all the results for a single day.
for example select * from table where created_date > = 29 December 2009 ' and created_date < = 30 December 2009 "."
Game results = 5 records
However,.
"Select * from table where created_date > = 29 December 2009 ' and created_date < = 29 December 2009.
OR
Select * from table where created_date > = 30 December 2009 ' and created_date < = 30 December 2009 "."
return 0 records.
Why is it so? I seem to be missing something obvious. Pointers would be really usefulSelect * from table where created_date > = 29 December 2009 ' and created_date<>
date means all created between 29 December 2009 00:00:00 ' and 30 December 2009 00:00:00 '
Select * from table where created_date > = 29 December 2009 ' and created_date<>
date means all created between 29 December 2009 00:00:00 ' and 29 December 2009 00:00:00 '
Select * from table where created_date > = 30 December 2009 ' and created_date<>
date means all created between 30 December 2009 00:00:00 ' and 30 December 2009 00:00:00 '
If you need manage correctly the time...
select * from table where created_date >='29-Dec-2009' and created_date < '30-Dec-2009'.
To get only the records at any time during the 29 dec.
select * from table where created_date >='30-Dec-2009' and created_date < '31-Dec-2009'.
To get only the records at any time during the Dec-30.
select * from table where created_date >='29-Dec-2009' and created_date < '31-Dec-2009'.
To get only the records at any time during the 29th Dec and Dec - 30.
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]
Maybe you are looking for
-
How can I stop him adding that pop multiple bookmarks - up to fill the width of the screen?
Whenever I try to add more than one link to my favourites, the pop-up that asks to add these links fills the width of the screen. It happens when I try to add all of the current tabs to Favorites, as well as when I use the add on, multi links. This m
-
XPRT: How to remove the battery cover?
How to remove the cover of the battery on the XPRT correctly? You lift up the slot on the bottom next to the mic or what? Nothing really seems to drag...
-
I am running windows XP in IE 8. Do I need IE 9 and if so it will just work?
Original title: should I me am running windows XP in IE 8. Do I need IE 9 and if so it will just work? My window to update says I can download IE 9. Do I really need? And my XP system will work correctly without problem with him?
-
How to upgrade my laptop envy6 on Blu - ray
How to upgrade my laptop envy6 on Blu - ray From Internet Explorer Original title: envy6-portable
-
Impossible to take more than 5 to 10 characters of color
Hello I bought a Deskjet 1050 printer all in one last month. Because yesterday I took (A4 size) color photo prints. After 5 pages, the level of (small model 802 of cartridge) ink cartridge shows empty. Please let me know normally how many pages it wi