Select the last record of each month
Hello
to select the last docnumber and qty of every month
Structure
Name Null? Type
------------------------------- -------- ----
PRODUCTCODE NUMBER
NUMBER NUMBER
DATE OF PLANFORMONTH
NUMBER OF CLEXPECTEDQTY
NUMBER OF CLCONFIRMQTY
NUMBER OF CLFGBUFFERQTY
NUMBER OF CLTOTPRINTBUFFER
in this select query if I take the sum he required all records where, as I want the last record of each month
SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.
SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)
GROUP BY productcode, (planformonth)
Sandy
Hello
Thanks its working now the code is written as below:
SELECT * FROM
(SELECT
e.*,
ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r
Of
E FGSALESPLAN)
WHERE r = 1 AND
entryvalid = 'Y '.
order by Number
Sandy
Tags: Database
Similar Questions
-
use to insert the last day of each month
Hi, I wrote this code but it did not insert the 20 December and it is January 1, and next time running is 31 January... I would like to work to make this insert every last day of each month...
I don't know if it's because I assigned the date 31-10... In November it's just but December has not...begin sys.dbms_job.submit(job => :job, what => 'INSERT INTO hisrtu SELECT rtunum, linked, dbchkd, chaqty, dbvald, ctrltr, meaadj, qtyrtu, month, year, entity, rtunam FROM qtyrtu;', next_date => to_date('31-10-2010 01:00:03', 'dd-mm-yyyy hh24:mi:ss'), interval => 'SYSDATE +30'); commit; end; /
Best regards, hope you can help me.
I use oracle 9iHello
If you want the job to run at 02:00 the last day of the next month, then the desired argument is:
interval => 'ADD_MONTHS (TRUNC (SYSDATE, ''MONTH''), 2) - (22 / 24)'
In other words, if she finishes running at 02:30 on 31 January, then
TRUNC (SYSDATE, 'MONTH') will be at 00:00:00 January 1
ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), 1) will be March 1st at 00:00:00
ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), - 1) (22 / 24) will be 22 hours earlier, i.e. 02:00 on the last day of February.logandro wrote:
I don't know if it's because I assigned the date 31-10... In November it's just but December has not...Do you mean this line?
next_date-online to_date (October 31, 2010 01:00:03 ',' dd-mm-yyyy hh24:mi:ss'),
I don't think that's a problem. The next_date specifies only when it work baptisms. I guess he ran on October 31; you said it was running well on 30 November, 30 days after that. Something has to happen after November 30.
Note that the interval argument is relative when the task completes. If a task takes 30 minutes to run, then
interval => 'SYSDATE +30'
means that, if it turns to
01:00:03 October 31, then it will run again about
01:30:03 November 30, around
02:00:03 on December 30.
02:30:03 January 29 and so on. If your business does that for a few seconds, it won't matter much.If you decide to use LAST_DAY, don't forget not that the hours-minutes-seconds referring LAST_DAY are the same as those of his argument.
-
Select the last value for each day of the table
Hello!
I have a table that contains several measures for each day. I need two queries on this table, and I'm not sure how to write them.
The table stores the rows (sample data)
Explanation of the data in the sample table:*DateCol1 Value Database* 27.09.2009 12:00:00 100 DB1 27.09.2009 20:00:00 150 DB1 27.09.2009 12:00:00 1000 DB2 27.09.2009 20:00:00 1100 DB2 28.09.2009 12:00:00 200 DB1 28.09.2009 20:00:00 220 DB1 28.09.2009 12:00:00 1500 DB2 28.09.2009 20:00:00 2000 DB2
We measure the size of the data files belonging to each database to one or more times a day. The value column indicates the size of the files of database for each database at some point (date in DateCol1 European model).
What I need:
Query 1:
The query must return to the last action for each day and the database. Like this:
Query 2:*DateCol1 Value Database* 27.09.2009 150 DB1 27.09.2009 1100 DB2 28.09.2009 220 DB1 28.09.2009 2000 DB2
The query should return the average measurement for each day and the database. Like this:
Could someone please help me to write these two queries?*DateCol1 Value Database* 27.09.2009 125 DB1 27.09.2009 1050 DB2 28.09.2009 210 DB1 28.09.2009 1750 DB2
Please let me know if you need further information.
Published by: user7066552 on September 29, 2009 10:17
Published by: user7066552 on September 29, 2009 10:17Why two queries when it suffice ;)
SQL> select dt 2 , db 3 , val 4 , avg_val 5 from ( 6 select dt 7 , val 8 , db 9 , row_number () over (partition by db, trunc (dt) 10 order by dt desc 11 ) rn 12 , avg (val) over (partition by db, trunc (dt)) avg_val 13 from test) 14 where rn = 1 15 order by dt 16 / DT DB VAL AVG_VAL --------- ----- ---------- ---------- 27-SEP-09 DB2 1100 1050 27-SEP-09 DB1 150 125 28-SEP-09 DB2 2000 1750 28-SEP-09 DB1 220 210
-
Hi can someone help me to achieve this scenario...
Thanks in advance...
Hello
Make the scenario for each interface and expand when the script option is planning.
Scheduling---> option execution---> select month (day of week)---> monthly date = last & Sunday and schedule accordingly.
Let me know
Thank you
-
In the following query, I want only one record for Robert (later) and a record for all peoples in R1. Tried several joins, but do not know why it does not work
drop table r1;
create table r1
(
index_id NUMBER,
first name VARCHAR2 (10),
created DATE by DEFAULT SYSDATE
);
Insert into r1 (index_id, name) VALUES (1, 'Joe');
Insert into r1 (index_id, name) VALUES (2, 'Robert');
Insert into r1 (index_id, name) VALUES (3, 'John');
commit;
drop table r2;
create table r2
(
index_id NUMBER,
Field1 VARCHAR2 (10),
VARCHAR2 (10) Field2.
created DATE by DEFAULT SYSDATE
);
Insert into r2 (index_id, Field1, Field2) VALUES (2, "REC1", "OLD");
Insert into r2 (index_id, Field1, Field2, created) VALUES (2, 'REC1', 'NEW', sysdate + 1);
commit;
Select r1.*, r2.* from r1, r2,
(
Select f.index_id as ind, f.field1, max (f.created) as last
R2 f
F.index_id, f.field1) abc
where r1.index_id = r2.index_id
and r2.created = abc.latest
and r2.index_id = abc.ind (+);
.
Like this?
-------------------------------------------------------
SELECT *.
SINCE r1,.
(SELECT f.index_id AS ind, f.field1, MAX (f.created) AS last
R2 f
F.index_id, f.field1) r2
WHERE r1.index_id = r2.ind (+);
-------------------------------------------------------
INDEX_ID FIRST NAME CREATED IND FIELD1 LATEST 2 Robert 04/07/2013-06:43 2 REC1 05/07/2013-06:43 3 John 04/07/2013-06:43 1 Joe 04/07/2013-06:43 If not then please post your results
See you soon,.
Manik.
-
Select the last disk in the history table
How to select the last record in a history table? the example data is
< p >
Product EffectiveDate
prod1 01/01/1980
prod1 01/01/1990
prod1 01/01/2000
prod2 02/02/1980
prod2 02/02/2000
< /p >
< p >
The expected result is
Product EffectiveDate
prod1 01/01/2000
prod2 02/02/2000
< /p >
Assuming that there is a single line with max (effectivedate) for a given product
SELECT product, attrib1, attrib2, ... , max_effective_date FROM (SELECT product, attrib1, attrib2, ... , effectivedate, max( effectivedate ) over (partition by product) max_effective_date FROM history_table) WHERE effectivedate = max_effectivedate
should work.
Justin
Published by: Justin cave on October 30, 2008 18:32
Formatting changes
-
How to select the last 3 records in a table?
I have a table named HRM_ATTENDANCE
as follows
the table contains the record of leave of employees as followsName Type Nullable Default Comments ------------ ------------ -------- ------- -------- LEAVEDATE DATE EMPLOYEECODE VARCHAR2(8) LEAVETYPE VARCHAR2(4) APPROVEDBY VARCHAR2(8) Y FEEDBY VARCHAR2(8) Y FEEDTIME DATE Y REMARKS VARCHAR2(50) Y
I want to select the last 3 leaves (records) to employeecode "00001" so I don't know the what are the dates of the leave. in easy words I want to choose the folder where leavedate > = 5 June 2013 ", but I don't know any dates."LEAVEDATE EMPLOYEECODE LEAVETYPE APPROVEDBY FEEDBY FEEDTIME REMARKS ----------- ------------ --------- ---------- -------- ----------- -------------------------------------------------- 6/1/2013 00001 CL 6/3/2013 00001 EL 6/5/2013 00001 CPL 6/7/2013 00001 SL 6/9/2013 00001 CL
Select * from HRM_ATTENDANCE where rownum<=3 order="" by="" leavedate="">=3>
-
Select the last 10 records in a table
Oracle9i. I am trying to select the last 10 numbers in a table with this command series
but it's not not selecting the most recent serial number 10. How to do?select serial from tab_42 where employeecode='00001' and rownum<=10 order by serial desc;
The rownum clause is applied before the order by clause, one must use a subquery...
select * from (select serial from tab_42 where employeecode='00001' order by serial desc) where rownum<=10;
-
Cursor Oracle return only the last record
I am a newbie in oracle stored proc. I tried to select data using the slider, but it only return last record. The recording must be greater than 1.
CREATE or REPLACE procedure MySchema.Test (myrefcur on sys_refcursor)
Is
Begin
declare
Cursor C1 IS
Select mySerialNum from TableA;
MyRecord C1% rowtype;
Begin
Open C1;
Loop
Fetch C1 into myrecord;
When the output C1% NotFound;
Open for Myrefcur
Select SerialNumB from TableB where SerialNumB = myrecord.mySerialNum;
End loop;
Close C1;
End;
end;
However, it only returns the last record in the list.
Original case *.
The original code is as below:
1st, I'll need to select a list of ImageSerialNum of ImageSerial
* 1 query:
Select A.ImageSerialNum from ImageSerial A, ProductionOrder B, Bom C
Where A.ProductionOrderID = B.ProductionOrderID And B.Assembly_Num = C.Model_Num and
B.Revision = C.Revision And B.EngRevision = C.EngRevision and
C.Bom_ID = passInVariable* and C.FactoryID = "7"
2nd, I'll need to check the process of EACH series with the code below:
* Low code a return process for 1 series only.
Select t.processid, t.processname, t.assembly_num, t.revision, t.engrevision of
(Select p.ProcessID, p.ProcessName, in. Assembly_Num, in. review, in. EngRevision, im.imageserialnum
Process p, Routesequence rs, Imageserial im, ProductionOrder in.
Where im. ImageserialNum = SerialNum* and p.ProcessID = rs. ProcessID
And rs. RouteID = in. RouteID and rs. SequenceID = im. NextRouteSequence
And in. ProductionOrderID = im. ProductionOrderID AND IM. STATUS OF '0'
UNION
SELECT A.REWORKROUTEID AS PROCESSID PROCESSNAME AS B.ROUTENAME, C.ASSEMBLY_NUM, C.REVISION, C.ENGREVISION, a.imageserialnum
OF IMAGESERIAL A, B OF ROAD, PRODUCTIONORDER C
WHERE A.REWORKROUTEID = B.ROUTEID AND A.IMAGESERIALNUM = SerialNum*.
AND A.PRODUCTIONORDERID = C.PRODUCTIONORDERID and a.status = '0') t
After that, I would like to combine the two in 1 stored proc code.in this case, you just want to join the two applications to use in the FROM clause
As I don't have your tables, I created two tables, each representing the results of your queries. Substitute the names of table with your queriesSQL> drop table master 2 / Table dropped. SQL> drop table details 2 / Table dropped. SQL> SQL> create table master 2 (ImageSerialNum varchar2(25)); Table created. SQL> SQL> SQL> insert into master values ('Serial1'); 1 row created. SQL> insert into master values ('Serial2'); 1 row created. SQL> insert into master values ('Serial3'); 1 row created. SQL> insert into master values ('Serial4'); 1 row created. SQL> insert into master values ('Serial5'); 1 row created. SQL> SQL> create table details 2 (ImageSerialNum varchar2(25) 3 ,ProcessID number 4 ,ProcessName varchar2(25) 5 ); Table created. SQL> SQL> insert into details values ('Serial1', 1, 'Process1'); 1 row created. SQL> insert into details values ('Serial3', 3, 'Process3'); 1 row created. SQL> insert into details values ('Serial5', 5, 'Process5'); 1 row created. SQL> SQL> select m.imageserialnum 2 , d.processid 3 , d.processname 4 from master m 5 left outer 6 join details d 7 on (m.imageSerialnum = d.imageserialnum) 8 order by m.imageserialnum 9 / IMAGESERIALNUM PROCESSID PROCESSNAME ------------------------- ---------- ------------------------- Serial1 1 Process1 Serial2 Serial3 3 Process3 Serial4 Serial5 5 Process5
your query will be something like
select m.imageserialnum , d.processid , d.processname from (
) m left outer join ( -
Find the 2nd Sunday of each month in a report
Hello
I have the data of EMP_Name and Join_Date. I have to build a dashboard report where
- In the dashboard, there is a command prompt. If I select a year and a month then, the report is expected to show that the data of the respective month.
- This report will show the employees who joined the company only after the 2nd Sunday of each month until the end of the month.
Inputs/suggestions, how to build it?
Thanks in advance.
You have a question, Yes... a SQL query... OBIEE do not mean SQL but LSQL, your query will be not really usable like this...
You're right, it seems that when the first day of the month is a Saturday he jump 1 week...
The correct formula for the 3rd Friday is:
TIMESTAMPADD (SQL_TSI_DAY, (14 + 6-CASE WHEN DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE)) = 7 THEN 0 END ELSE DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))
If instead of CURRENT_DATE you want to use your own column date just to replace in the formula and it works.
-
Display total records with the last record
Hi all
I have the following tables:
create the table TRY_date_detail
(
item_date date,
number of item_order
);
create the table TRY_date_master
(
date of master_date,
number of date_amount
);
Insert all
IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 1)
IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 2).
IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 3)
IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 4)
IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 5)
IN TRY_date_master values (to_date('01-01-2011','DD-MM-YYYY'), 6432)
IN TRY_date_master values (to_date('01-01-2011','DD-MM-YYYY'), 1111)
IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 11)
IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 12)
IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 13)
IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 14)
IN TRY_date_master values (to_date('11-08-2012','DD-MM-YYYY'), 8913)
IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 21)
IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 22)
IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 23)
IN TRY_date_master values (to_date('09-03-2014','DD-MM-YYYY'), 1234)
IN TRY_date_detail values (to_date('11-03-2014','DD-MM-YYYY'), 33)
Select * twice;
-My query is:
SELECT ITEM_DATE, ITEM_ORDER, DATE_AMOUNT NULL
OF TRY_date_detail
WHERE ITEM_DATE IN (SELECT DISTINCT master_date OF TRY_date_master)
UNION
SELECT MASTER_DATE, NULL, SUM (DATE_AMOUNT)
OF TRY_DATE_MASTER
MASTER_DATE GROUP;
-My query result:
ITEM_DATE ITEM_ORDER DATE_AMOUNT
January 1, 11 12:00:00 AM 1 (null)
January 1, 11 12:00:00 AM 2 (null)
January 1, 11 12:00:00 AM 3 (null)
January 1, 11 12:00:00 AM 4 (null)
January 1, 11 12:00:00 AM 5 (null)
January 1, 11 12:00:00 AM (null) 7543
11 Aug 12 12:00:00 AM 11 (null)
11 Aug 12 12:00:00 AM 12 (null)
August 11, 12 noon 13 (null)
11 Aug 12 12:00 14 (null)
11 Aug 12 12:00:00 AM (null) 8913
9 March 14 12:00:00 AM 21 (null)
9 March 14 12:00:00 AM 22 (null)
9 March 14 12:00:00 AM 23 (null)
9 March 14 12:00:00 AM (null) 1234
-What I need, is to display the Date_amount with the last line of each date as follows:
ITEM_DATE ITEM_ORDER DATE_AMOUNT
January 1, 11 12:00:00 AM 1 (null)
January 1, 11 12:00:00 AM 2 (null)
January 1, 11 12:00:00 AM 3 (null)
January 1, 11 12:00:00 AM 4 (null)
January 1, 11 12:00:00 AM 5 7543
11 Aug 12 12:00:00 AM 11 (null)
11 Aug 12 12:00:00 AM 12 (null)
August 11, 12 noon 13 (null)
August 11, 12 12 00 14 8913 h
9 March 14 12:00:00 AM 21 (null)
9 March 14 12:00:00 AM 22 (null)
9 March 14 12:00:00 AM 23 1234
Thank you
Ferro
You have to JOIN to the table two
SQL> select item_date 2 , item_order 3 , decode(rno, cnt, date_amount) date_amount 4 from ( 5 select item_date 6 , item_order 7 , date_amount 8 , row_number() over(partition by item_date order by item_order) rno 9 , count(*) over(partition by item_date) cnt 10 from try_date_detail 11 join ( 12 select master_date, sum(date_amount) date_amount 13 from try_date_master 14 group 15 by master_date 16 ) 17 on item_date = master_date 18 ); ITEM_DATE ITEM_ORDER DATE_AMOUNT ------------------- ---------- ----------- 01/01/2011 00:00:00 1 01/01/2011 00:00:00 2 01/01/2011 00:00:00 3 01/01/2011 00:00:00 4 01/01/2011 00:00:00 5 7543 11/08/2012 00:00:00 11 11/08/2012 00:00:00 12 11/08/2012 00:00:00 13 11/08/2012 00:00:00 14 8913 09/03/2014 00:00:00 21 09/03/2014 00:00:00 22 09/03/2014 00:00:00 23 1234 12 rows selected. SQL>
-
How to get the second Monday of each month in a given date range?
In Oracle forms, how to get the second Monday of each month in a given date range?
I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?
WITH month_range AS
(
SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month
, TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month
OF the double
)
SELECT NEXT_DAY (6 + ADD_MONTHS (first_month
, LEVEL - 1
)
, 'MONDAY '.
) AS second_monday
OF month_range
CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)
;
Thanks in advance.
Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below
SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.
THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')
Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7
END AS second_day
FROM (SELECT SYSDATE startdate,
SYSDATE + 300 enddate
THE DOUBLE)
CONNECT BY LEVEL<=>=>
-
for the 25th day of each month in Date function
Dear all,
I want to want to get the 25th day of each month
as.
Select sysdate from dua.
ConcerningSQL> select trunc(sysdate,'MM')+24 "Day" from dual; Day --------- 25-MAY-13
-
How to get the date for the first Monday of each month
Dear members,
How to get the date for the first Monday of each month.
I wrote the following code
SELECT decode (to_char (trunc (sysdate + 30, 'MM'), 'DAY'), 'MONDAY', trunc (sysdate + 30, 'MM'), NEXT_DAY (trunc (sysdate + 30, 'MM'), "LUN")) FROM DUAL
But he looks at complex bith.
Abhishek
Published by: 9999999 on 8 March 2013 04:30Use the IW format - it will make independent NLS solution. And all you need is truncated 7th day of each month using IW:
select sysdate current_date, trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month from dual / CURRENT_D FIRST_MON --------- --------- 08-MAR-13 04-MAR-13 SQL>
Here is the list of the first Monday of the month of this year:
with t as( select add_months(date '2013-1-1',level-1) dt from dual connect by level <= 12 ) select dt first_of_the_month, trunc(dt + 6,'iw') first_monday_the_month from t / FIRST_OF_ FIRST_MON --------- --------- 01-JAN-13 07-JAN-13 01-FEB-13 04-FEB-13 01-MAR-13 04-MAR-13 01-APR-13 01-APR-13 01-MAY-13 06-MAY-13 01-JUN-13 03-JUN-13 01-JUL-13 01-JUL-13 01-AUG-13 05-AUG-13 01-SEP-13 02-SEP-13 01-OCT-13 07-OCT-13 01-NOV-13 04-NOV-13 FIRST_OF_ FIRST_MON --------- --------- 01-DEC-13 02-DEC-13 12 rows selected. SQL>
SY.
-
The line of the last line of each table page is going to be missing.
Hi Experts,
In OBIEE 11.1.1.6.0, I have a report contains more than one line. "When I click on" PDF "Print", the last line of each table page line will be missing. " Why?
Are you facing the same case? How soluve this question? Thank you.Hey Kobe,
The question, looks lke a bug. Here's the work around, change the table view, click the properties of content next to the text "Table" (at the top of the columns and measures) in the layout-> position In Border pane to choose custom and select only the bottom edge (horizontal line). Now export to pdf format, you must see the border for the last row on each page.
Kind regards
DpKa
Maybe you are looking for
-
How to choose a vcard for use in the automatic filling of Safari?
Recently, I cleaned my Contacts Apple and remove duplicates of myself. Apparently I deleted the one designated as my user vcard so even if I have one with all my contact information, I can't fill it with Safari (the little blue guy to the right of th
-
My iphone 6 ceased to accept my password! When I enter my password, the screen turns black with a circle of rotation and goes back to the password screen. If I type a bad password the phone buzz and vibrate. I reset my phone and saved on Itues wi
-
T1800 show me a flashing bar / line
Hello, guys I have a problem and a few questions... I found a very old Toshiba notebook, a T1800 and I have no manual and no drivers for this old thing... and he started... It always show me a flashing bar / line... Can someone help me?I don't want t
-
I have an array of clusters and each group has dozens of controls in there. I want to go through all the groups table and change the value of a specific control. Currently, I use the property value in the array node to get a table 1 d of clusters, a
-
Hello I'm a bit new to these must therefore ask from you experts. Tried to browse this forum, but did not find an answer to this question. I need to get my AV system with only the RJ45 connection network. However, I don't have cables on show so I nee