query of the month
Hello11g, I want to run a query that finds SQL_ID of January (the last month at any time I run this query, it must run on the 5th day of each month). And that's what's happening:
SQL> select to_char(sysdate, 'mm')-01 from dual;
TO_CHAR(SYSDATE,'MM')-01
------------------------
1
SQL> select sql_id from v$sqlarea where LAST_ACTIVE_TIME like '%(select to_char(sysdate, 'mm')-01 from dual)%';
select sql_id from v$sqlarea where LAST_ACTIVE_TIME like '%(select to_char(sysdate, 'mm')-01 from dual)%'
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
How can I do?Thanks for help.
where LAST_ACTIVE_TIME >= trunc(trunc(sysdate,'mm')-1,'mm')
and LAST_ACTIVE_TIME < trunc(sysdate,'mm')
Tags: Database
Similar Questions
-
Need to query for the monthly total compensation
Hi all
Please I need a query that he will show me the name, identification number, and the total compensation
total compensation = gain Total - Total deduction
I can find the total compensation in pay stubs, but I need the query to do some reports
Thanks in advanceThe modified query is less. You can change the names of Classification if needed.
Select women's wear. EMPLOYEE_NUMBER, sum (DECODE (pec.classification_name,
"Involuntary deductions", ((-1))
* TO_NUMBER (prrv.result_value)).
'Statutory deductions', ((-1))
* TO_NUMBER (prrv.result_value)).
"Earnings", TO_NUMBER (prrv.result_value)
) Paid_Value
of apps.pay_payroll_actions App
apps.pay_assignment_actions PAA
apps.pay_run_results prr
apps.pay_run_result_values prrv
apps.pay_input_values_f piv
apps.pay_element_types_f pet
apps.pay_element_classifications pec
apps.per_all_assignments_f ADP
apps.per_all_people_f women's wear
where App. PAYROLL_ACTION_ID = PAA. PAYROLL_ACTION_ID
and the PAA. ASSIGNMENT_ID = ADP. ASSIGNMENT_ID
and the PAA. EFFECTIVE_DATE between the ADP. EFFECTIVE_START_DATE and ADP. EFFECTIVE_END_DATE
and the PAA. ACTION_TYPE = 'R '.
- and the PAA. BUSINESS_GROUP_ID =: BG_ID
- and the PAA. ACTION_STATUS = 'C '.
and prr. ASSIGNMENT_ACTION_ID = PAA. ASSIGNMENT_ACTION_ID
and prr. RUN_RESULT_ID = prrv. RUN_RESULT_ID
and prrv. INPUT_VALUE_ID = piv. INPUT_VALUE_ID
and piv.NAME = 'value to pay '.
and domestic animals. ELEMENT_TYPE_ID = prr. ELEMENT_TYPE_ID
and domestic animals. CLASSIFICATION_ID = pec. CLASSIFICATION_ID
and the PAA. "EFFECTIVE_DATE =: PAYROLL_DATE - FEBRUARY 23, 2012 '-: PAYROLL_DATE - FEBRUARY 23, 2012"
and women's wear. EMPLOYEE_NUMBER =: EMP_ID
and ADP. PERSON_ID = papf.person_id
and the PAA. EFFECTIVE_DATE between women's wear. EFFECTIVE_START_DATE and women's wear. EFFECTIVE_END_DATE
Group of women's wear. EMPLOYEE_NUMBER -
query for the first day of the month
Hi all
How to get the first day of the month in the sql query.
SQL> select trunc(sysdate,'mm') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL> select trunc(sysdate,'month') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL> select trunc(sysdate,'mon') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL>
-
Select the query to select the month range based on the current date.
It's the database 10 g oracel.
I want to choose two months of data in the table. But these two months should be based on the current date.
For example.
If I run the select query on July 7, 2013, then the query must ignore the current month being July 2013 and last month, which is June 2013 and it shoud select only may 2013 and April 2013.
Can someone help me how to make this request.
SELECT *.
FROM my_table
WHERE my_date > = TRUNC (ADD_MONTHS (sysdate,-3), 'MY') - first day of the month 3 months ago
AND my_date< trunc(add_months(sysdate,-1),'mon')="" --="" first="" day="" of="" last="">
-
A query with the weeks/months/quarters without filling data
During recovery of monthly data from any data source, experts how CF (which I am not one) creates results for the time intervals where there is no results? I.E. event data to draw per month, how can I show that there can be no activity for a given month? Thanks in advance.There is a way to make more efficient approach to dempster.
Step 1: run your query from the database. (1 queries)
Step 2 - create a cold fusion query to get all years-months in the range of dates of interest (2 requests)
Step 3 - make a query of queries for years-monthly query 2 that are not in the application 1. (3 requests)
Step 4: make a query of queries that questions 1 and 3 trade unions. -
How to calculate the first day of the month following in BI Publisher
I need to be able to calculate the first day of the month of a date field in a BI Publisher model. The field name is COL_CLM_180 and contains a date in the format "YYYY-MM-DD". I have found so far any documentation that still gives me an idea of what to do.
Any help or advice would be appreciated
Hi - thank you very much for your help. Your last answer got me going in the right direction and I indeed was dense. I don't know why I don't think to the calculation in the original query. I put the statement: TRUNC (ADD_MONTHS(A.COL_CLM_180,1), 'MM') in a column in the query of conduct and it has worked flawlessly. Thank you - thank you - thank you.
-
Display all the months in a year using sql
Hello
Hi guys I need to generate all the months in a year as
January
February
.
.
.
.
.
December
I need to use this function,
so do me a query to generate months
Thanks in advance
Select to_char (to_date(level,'mm'), 'fmMonth') month
of the double
connect by level<=>=>
/
MONTH
---------
January
February
March
April
May
June
July
August
September
October
NovemberMONTH
---------
December12 selected lines.
SQL >
SY.
-
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
SELECT first_thursday + (7 * (LEVEL - 1)) AS week_start_date, first_thursday + (7 * LEVEL) - 1 AS week_end_date FROM ( SELECT TRUNC(p_from_date + 4, 'IW') - 4 AS first_thursday, -- Week should start the pre ceeding THURSDAY based on the Start Date TRUNC( p_to_date + 4, 'IW') - 5 AS last_wednesday FROM ( SELECT to_date('01-JAN-2013') AS p_from_date, NVL(to_date('31-DEC-2013'), SYSDATE) AS p_to_date FROM dual ) parms ) end_points CONNECT BY LEVEL <= ( last_wednesday + 1 - first_thursday)/7;
Currently, this is the result I get (I'm only including the months of January and December here).
Week_Start_Date Week_End_Date 27-DEC-12 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 06-FEB-13
December:
28-NOV-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
01-JAN-13 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 31-JAN-13
February:
01-FEB-13 06-FEB-13 07-FEB-13 13-FEB-13 14-FEB-13 20-FEB-13 21-FEB-13 27-FEB-13 28-FEB-13 28-FEB-13
November:
31-OCT-13 06-NOV-13 07-NOV-13 13-NOV-13 14-NOV-13 20-NOV-13 21-NOV-13 27-NOV-13 28-NOV-13 04-DEC-13
December:
01-DEC-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13 26-DEC-13 31-DEC-13
Hello
Roxyrollers wrote:
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
- First_thursday SELECT + (7 * (LEVEL - 1)) AS week_start_date,
- first_thursday + (7 * LEVEL)-1 AS week_end_date
- Of
- (
- SELECT TRUNC (p_from_date + 4, 'IW') - 4 AS first_thursday,-week should start to perform the pre-mounted THURSDAY based on the Start Date
- TRUNC (p_to_date + 4, 'IW') - 5 AS last_wednesday
- Of
- (
- SELECT to_date('01-JAN-2013') AS p_from_date,
- NVL (to_date('31-Dec-2013'), SYSDATE) AS p_to_date
- OF the double
- ) parms
- ) end_points
- CONNECT BY LEVEL<= (="" last_wednesday="" +="" 1="" -="">=>
Currently, this is the result I get (I'm only including the months of January and December here).
- Week_Start_Date Week_End_Date
- DECEMBER 27, 12 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 FEBRUARY 6, 13
December:
- NOVEMBER 28, 13 4 DECEMBER 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
- JANUARY 1, 13 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 JANUARY 31, 13
February:
- 1ST FEBRUARY 13 FEBRUARY 6, 13
- 7 FEBRUARY 13 FEBRUARY 13, 13
- 14 FEBRUARY 13 FEBRUARY 20, 13
- 21 FEBRUARY 13 FEBRUARY 27, 13
- 28 FEBRUARY 13 FEBRUARY 28, 13
November:
- 31 OCTOBER 13 NOVEMBER 6, 13
- 7 NOVEMBER 13 NOVEMBER 13, 13
- 14 NOVEMBER 13 NOVEMBER 20, 13
- 21 NOVEMBER 13 NOVEMBER 27, 13
- NOVEMBER 28, 13 4 DECEMBER 13
December:
- 1ST DECEMBER 13 DECEMBER 4, 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
- 26 DECEMBER 13 DECEMBER 31, 13
Why the "weeks" in November, have all 7 days, while the "weeks" in the first or the last week in the other month usually have less? (For example, February 28 is a 'week' alone.)
The following works for the other months:
WITH all_days AS
(
SELECT DATE "2013-01-01' + LEVEL - AS a_date 1
OF the double
CONNECT BY LEVEL<=>=>
)
SELECT DISTINCT
More GRAND (TRUNC (a_date + 4, 'IW') - 4)
, TRUNC (a_date, 'MONTH')
) AS week_begin
, The LEAST (TRUNC (a_date + 4, 'IW') + 2
TRUNC (LAST_DAY (a_date))
), Week_end
Of all_days
ORDER BY week_begin
;
Output:
WEEK_BEGIN WEEK_END
----------- -----------
January 1, 2013 January 2, 2013
January 3, 2013 January 9, 2013
January 10, 2013 January 16, 2013
January 17, 2013 January 23, 2013
January 24, 2013 January 30, 2013
January 31, 2013 January 31, 2013
February 1, 2013 February 6, 2013
February 7, 2013 February 13, 2013
February 14, 2013 February 20, 2013
February 21, 2013 February 27, 2013
February 28, 2013 February 28, 2013
...
November 1, 2013 November 6, 2013
November 7, 2013 November 13, 2013
November 14, 2013 November 20, 2013
November 21, 2013 November 27, 2013
November 28, 2013 November 30, 2013
December 1, 2013 December 4, 2013
December 5, 2013 December 11, 2013
December 12, 2013 December 18, 2013
December 19, 2013 December 25, 2013
26 December 2013 31 December 2013
-
How to find values between two months (from January to the month prompted)?
Hello
I need to create a filter on the name of the month. That is to say of January of the year for the 'guest' month of guest of dashboard.
Ex: If I ask year and month of year in 2013 and March respectively. I should get values for Jan 2013, 2013 Feb and March 2013.
I can't try one between because that it only works on numeric values.
I can't have a number of months in prompt because this isn't the condition and I am not allowed to.
I tried the below query report filter
«Sun - times» "" Fiscal month "< = (select"Dim - time". "" Fiscal month "where"Dim - time. " ("' Name of the fiscal month ' = @{PMonth}) PMonth where is the Variable of presentation" for months ".
But it's not working
Help, please
Thank you
If it is 11g then try to use the column twice.
Thank you
-
How to cancel a subscription to the month?
How to cancel a subscription to the month?
Hi Lynn,
As you have filed your application on the Adobe Reader page, I want to tell you that it is a free software from Adobe.
I guess you want to cancel the monthly subscription of Acrobat.
I recommend you consult the following link for your subscription canceled.
Cancel your subscription or membership. Acrobat, services Cloud of Document PDF
The other option would be to contact Adobe support team for the cancelled subscription.
Follow the link to connect with them.
http://helpx.Adobe.com/x-productkb/global/Service1.html
Please click on the blue button "still need help" to connect with one of the Adobe executives and get your fixed query.
Concerning
Sukrit diallo
-
How to set the filter criteria for the month and the year to aid in the timestamp input field?
Hello
I use jdev 11.1.2.3.
I have a problem with the generation of reports, I have a report table that is in the form of VO (query based) and I want to search this table in the month and year of the basic
but in this table (query) This timestamp field of having value based on... How to do a search with the name of the month and year only... Here I totally use vo base query to generate a
reports... Anyone can guide me.
Thank you.
I want to create a drop-down list for month + year as an executable parameters with bind variable no matter what idea this subject, my attribute here is TimestampFormat.
Then add to your sql query something like:
WHERE extract (your_timestamp_column MONTHS) =: monthBindVar
OR an extract (YEAR your_timestamp_column) =: yearBindVar
and add monthBindVar and yearBindVar as a bind variable to your view object.
Then you can use it as a ExecuteWithParams operation (or manually set these bind variables and execute the query)
Dario
-
With separate SQL query and the counter is wrong.
Hello
I have another problem with a query.
The following data:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
And my request:CREATE TABLE TABLE_1 ( "ORDER_NR" VARCHAR2 (12) , "PRIORITY" VARCHAR2 (2) , "WO_STATUS" VARCHAR2 (1) , "STATUS_DATE" DATE , "ART_NR" VARCHAR2 (9) , "DESCRIPTION" VARCHAR2 (255) , "PRICE" VARCHAR2 (10) ); CREATE TABLE TABLE_2 ( "ART_NR" VARCHAR(9) , "MODELL" VARCHAR2(10) , "MANUFACT" VARCHAR2(20) ); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('05-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('06-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT6'); COMMIT;
And the result:SELECT T1.ART_NR , T2.MODELL , SUM(ROUND(T1.PRICE, 2)) AS TOTAL_PRICE , COUNT(*) AS QTY , TO_CHAR(T1.STATUS_DATE, 'MON-RR') AS MONTH FROM TABLE_1 T1, TABLE_2 T2 WHERE T1.WO_STATUS = 'U' AND T1.ART_NR = T2.ART_NR AND TO_CHAR(T1.STATUS_DATE, 'MON-RR') = 'FEB-13' GROUP BY T2.MODELL , T1.ART_NR , TO_CHAR(T1.STATUS_DATE, 'MON-RR')
My problem now is the OTY ist wrong field should count how many times the equipment was in service in Feb - 13 and group them by "MODEL" the production area is not interesting to me, but this is my problem, a model can have several Manufacter and so I had a bad count for my Qty.ART_NR MODELL TOTAL_PRICE QTY MONTH --------- ---------- ----------- ---------- ------ 018743356 VACCUM 559916.16 96 FEB-13 005667821 LASER 173936.48 48 FEB-13 005231987 X-RAY1 120006 24 FEB-13
The next step that I need is to group the result also by type of Service (annual or biannual), like this:
These values are only out of my head, not the table, just to show what I need.ART_NR MODELL TOTAL_PRICE QTY MONTH SERVICE_TYPE --------- ---------- ----------- ---------- ------ --------------------- 018743356 VACCUM 1234.56 4 FEB-13 ANNUAL 018743356 VACCUM 4423.48 10 FEB-13 BIENNIAL 005667821 LASER 4783.11 2 FEB-13 ANNUAL 005667821 LASER 1123.77 22 FEB-13 BIENNIAL 005231987 X-RAY1 8966.12 6 FEB-13 ANNUAL 005231987 X-RAY1 7826.44 12 FEB-13 BIENNIAL
Thanks for your help.
Hosts ReinhardHello
990524 wrote:
HelloWow it's great.
Thanks Frank.In my database, this query works like a charm, but I have a problem, sometimes the round command do not work then I get a total price of 1231.0000000000001, I
tried of TRUNCATES the value, but it's always the same value.Sorry, I can not re - create the problem.
And I put another line in the query that calculates the average price per model:
, ROUND ( SUM (g.price) / COUNT(*) ,2 ) AS average
Why not just
, ROUND (AVG (g.price), 2) AS average
?
and in this line, I have the same problem with bad ROUNDS.
Do you have an idea in this case?
No, sorry. If I can't get the same behavior, myself, it is not that I do.
Instead of ROUND, you can use TO_CHAR to (for example) display 2 digits after the decimal point. To_char will automatically round the result. Your front end (for example, the SQL * Plus COLUMN...) FORMAT command) can probably do the same thing.
-
Select records based on the monthly anniversary date
Hello
I have a table with a field of date_added and I want to select records from monthly birthday of this field.
for example. ID, Date_added
1, DECEMBER 10, 2012
2, 11 NOVEMBER 2012
3, 10 MARCH 2012
4, FEBRUARY 28, 2012
5, 30 DECEMBER 2012
So for January 10, 2013, I would like to return the documents 1 and 3 only
I started watching the extract function, but this little falls down to the records at the end of the month. For example, on 28 February, I also include records where 29, 30 or 31 is the day of date_added. So, in the above table, I won't return documents 4 and 5, but retrieves only returns 4.
Is there a simple function to make the request of birthday this month - have I missed something very obvious? Or I have to write a query to explicitly dates at the end of the month? So far I have not found a reasonable solution!
I use 11g
Thank youuser11259857 wrote:
Hi Al,.No I don't think that there is a flaw. For example, the 30 Jan is not the last day of the month, but is June 30. Thus, on 30 January I want only to interrogate all the dates falling on the 30th - 28 February, after already being interrogated on the 28 Jan. However, on 30 June, I would query the 30th of each month, as well as the 31 January, March, may, July, Aug, Oct, dec. February is a special case, being both shorter and a leap year
Thank you
Richard
Hi Richard,
so, we can assume that your needs are:
If the day is the last day of that month, interview the day of the other months being > = day of the current month.
That is to say:
Jan-30 = query only 30 other months
Jan-31 = query only 31 of the other monthsFeb-28 (non-leap years) = question 28, 29, 30 and 31 other months
29 February (leap year) = query 29,30,31 to other monthsMar-30 = query only 30 other months
Apr-30 = query 30 and 31 other monthsThis hypothesis is correct?
If so, then something like this should work:
WITH mydates(id, date_added) AS ( SELECT 1, TO_DATE('10-DEC-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL SELECT 2, TO_DATE('11-NOV-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL SELECT 3, TO_DATE('10-MAR-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL SELECT 4, TO_DATE('28-FEB-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL SELECT 5, TO_DATE('30-DEC-2012', 'DD-MON-YYYY') FROM DUAL ) SELECT id, date_added FROM mydates WHERE (:input_date = LAST_DAY(:input_date) AND TO_CHAR(:input_date,'DD') <= TO_CHAR(date_added, 'DD')) OR TO_CHAR(:input_date,'DD') = TO_CHAR(date_added, 'DD'); with input_date = 28/02/2013 id date_added 4 28/02/2012 5 30/12/2012
Kind regards.
AlPublished by: Alberto Faenza on 10 January 2013 15:21
Added example -
Hi experts,
Please let me know how to get registered for the 1st of the month by using the query, after passing a date in the query:
My queries below give me 1 license of the year and the last date of the month... Kindly hep...
Help appreciated,SELECT TRUNC(TO_DATE('24-JUN-2011'),'YEAR') FROM DUAL SELECT LAST_DAY(ADD_MONTHS('24-JUN-2011',12 - TO_NUMBER(TO_CHAR(SYSDATE,'mm')))) FROM DUAL
Thnx in advanceTRUNC(TO_DATE('24-JUN-2011'),'MM')
And he always will be always 1... ;)
-
Look at a rolling history of values by day of the month
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
I have a table t1 with 4 passes;
Here is an example of output from t1;CREATE TABLE t1 ( TV_ID NUMBER, TARGET_ID NUMBER, TARGET_START_DATE DATE, VALUE NUMBER);
I have an obligation to present the data in the following format;TV_ID TARGET_ID TARGET_START_DATE VALUE ----- --------- ----------------- ----- 3915 31 01/02/2012 12150 5000 31 15/02/2012 12155 5119 31 21/02/2012 12178 5354 31 25/02/2012 12196
There was a set of targets on 1 February 2012, then it was set to February 15, 2012, 21 February 2012 and finally 25 February 2012.TARGET_ID TARGET_START_DATE VALUE ----------- ----------------- -------- 31 01/02/2012 12150 31 02/02/2012 12150 31 03/02/2012 12150 31 04/02/2012 12150 31 05/02/2012 12150 31 06/02/2012 12150 31 07/02/2012 12150 31 08/02/2012 12150 31 09/02/2012 12150 31 10/02/2012 12150 31 11/02/2012 12150 31 12/02/2012 12150 31 13/02/2012 12150 31 14/02/2012 12150 31 15/02/2012 12155 31 16/02/2012 12155 31 17/02/2012 12155 31 18/02/2012 12155 31 19/02/2012 12155 31 20/02/2012 12155 31 21/02/2012 12178 31 22/02/2012 12178 31 23/02/2012 12178 31 24/02/2012 12178 31 25/02/2012 12196 31 26/02/2012 12196 31 27/02/2012 12196 31 28/02/2012 12196 31 29/02/2012 12196
We record a target_start_date, but for reasons of report our sales managers want to see a history of bearing of the target throughout the month/year.
I used Feb 2012 in the example above, but the same target will roll in March, April, 2012 etc.
This is the code I wrote to present the dates in chronological order.
It comes down to a year, but I'm fighting for this date of registration in the t1 table to present data in my required format.SELECT TRUNC (SYSDATE) - rn FROM ( SELECT ROWNUM rn FROM DUAL CONNECT BY LEVEL <= 365) UNION SELECT TRUNC (SYSDATE) FROM DUAL;
I saw the use of the model, WITH clause clause and temporary tables overall, but not quite answered to my question.
Any help greatly received.Hi, Phil,
user6336927 wrote:
Thanks for the reply of Peter. When I run your example I get;ORA-30484: lack of specification of the window for this function
If I remove the IGNORE NULLS the query runs, but the result is not quite right...
No, you must IGNORE NULLS, but IGNORE NULLS does not work in your version of Oracle, with a LAG. It works well with LAST_VALUE.
Try to use LAST_VALUE instead of LAG and IGNORE NULLS before law ')', like this:
... select last_value(sd.target_id ignore nulls) over (order by ad.report_date) target_id ,ad.report_date ,last_value(sd.sample_value ignore nulls) over (order by ad.report_date) sample_value from
The rest of the Peter query remains the same.
I would use LAST_VALUE for this job even in Oracle 11.2, because it does not require NVL.
LAG... IGNORE NULLS is a new feature of Oracle 11.2, which is also the first version that allows to IGNORE NULLS before or after the right ')'.
FIRST_VALUE... IGNORE NULLS works in Oracle 10.1 or more.
Maybe you are looking for
-
Unable to format hard drive for Windows
Hello, I need your help here! You receive the same error message saying: "Windows is unable to complete the format" when you try to format an external hard drive on your computer? Honestly, the hard drive of my dell computer recently asked just to ge
-
I need to transfer my iPod to my iTunes account library
My iTunes library disappeared after a new download. I always have my iPod classic with my entire library. How to restore my iTunes library?
-
Icons from left to right at the bottom of page
I have a footer at the bottom of my page.The foot is divided into 3 divThe first div is 2 columns wide, the second is wide from 8 columns and the third is broad 2 columns (from left to right)In the first div are text links. In the Middle div is my co
-
Hello worldCan someone tell me if it is possible to ddo sense followed in Eloqua and if so, how can we do?Thank youMonpetit
-
Joint internal and external joins in a SQL
Oracle 11g.There are four tables:T1 (primary key: pk_t1)T2 (primary key: pk_t2, fk_t2_ref_t1 foreign key)T3 (primary key: pk_t3, fk_t3_ref_t2 foreign key)T4 (primary key: pk_t4, fk_t4_ref_t3 foreign key)That's what I want to do: inner join between th