Help on sql
Hello
I have a table that has the month_key column. Need to find the current_month-36.
Month_key = output expected 201503 = 36 months before the current month which is 201203.
How can I get sql to get 201203 r. p. output format.
Thank you
Hello
Daniel wrote:
First I need to find the current month in this format 201503
and find currentmonth-36 which is 201203
Please help in obtaining sql.
Why do you need to find the current month if you already have a column (month_key) that contains the data? This is an example of why you should validate CREATE TABLE and INSERT for examples of data and instructions exactly the results you want from these data.
The function SYSDATE returns the current date, including the months.
In response, #2, you've seen how to find a DATE that was 36 months before another DATE.
ADD_MONTHS (SYSDATE-36)
is the DATE of 36 months ago to the day.
Use the TO_CHAR function if you want to display a DATE in a particular format, like this:
TO_CHAR (ADD_MONTHS (SYSDATE-36)
, "YYYYMM.
)
Tags: Database
Similar Questions
-
Under Update taking 2 h complete 3000 sets.
UPDATE ARR_TRANSACTIONS ARR
SET = NUMBER99
(SELECT ARR_1.NUMBER99
OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH
WHERE ARR_1.ARR_ID = BH. ARR_ID
AND BH. FLAG = "Y".
AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID
AND ARR_1.NUMBER9 IS NOT NULL
AND ROWNUM = 1)
WHERE ARR BATCH_ID = 26219
AND ARR. NUMBER99 IS NULL
I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.
Please help with SQL.
I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.
In the given situation, I would check:
- is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
- Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.
To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.
If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.
-
need help with SQL Server 2008 R2 deadlock uninstall process
I installed SQL Server 2008 R2 trial version on my PC running Windows Vista Ultimate, a day ago, but he placed himself completely in the disk partition (E :) that I specified. [i.e. I found some parts of the installation in my C:\program files as well as a USB as well].
I tried to uninstall SQL Server 2008 R2, but was only partially successful. I'm prevented from uninsalling the main parts using the programs and features Panel - that is "Microsoft SQL Server 2008 R2" and "Microsoft SQL Server 2008 R2 Setup (in English).
Still visible are:
1 C:\Program Files (x 86) \Microsoft SQL Server
2 C:\Program Files (x 86) \Microsoft Visual Studio 9.0
3 C:\ProgramData\Microsoft\Windows\Start demarrer\programmes\microsoft SQL Server 2008 R2
I would like your help to uninstall the other goals of SQL Server, so that I can do a clean install once more.
Any advice on how SQL Server 2008 R2 evaluation version must be correctly installed what a future unistall is not messy, would be welcome.
Hello
Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the SQL Server forums. Please post your question in the SQL Server forums.
http://social.msdn.Microsoft.com/forums/en/category/SQLServer
-
Need help with sql, and bash
Hi guys,.
My main problem/situation is when sqlplus returns no data (no message selected lines)
Bash shell script condition
echo $open_items
15 if [[$open_items == "0"]]
16. can
echo 17 0
18 else
19 1 echo
20 fi
and real sql is as follows:
elect the count (*) a table with a condition.
I get the output as follows:
+ open_items ='
COUNT (*)
----------
0'
+ echo 'COUNT (*)'---0
COUNT ()) - 0
+ [[
COUNT (*)
----------
0 == \0 ]]
+ echo 1
1
What to do so that I can get a number in the output of sql is my question because the condition of shell script is based entirely on sqlplus out. I tried set feedback off, but it does not help.
Any help would be much appreciated!
SQL lover wrote:
OK I try it and give you feedback
In fact, I take out execution of sql into a variable
MyVar = $(sqlplus-s/as sysdba)<>
Set echo off feedback off verify off trimsp head off pages 0
Select count (*) from dba_users;
output
EXPRESSIONS OF FOLKLORE)
echo myvar is $myvar
-
Dear team,
I have a technical dought based on PL/SQL.
I have a code like below
Select count (*)
in lcnt_al per_absence_attendances where person_id = p_person_id
and absence_attendance_type_id in (61,62)
and (p_from_date between date_start and date_end or p_to_date between date_start and date_end);
Scenario:
If I have a leave as records
Type of Date to Date Absence days
Leave annual 6 may 2015 10 May 15, 2015
Loss of wages may 16, 2015 may 20, 2015 5
If I use the above condition, it works very well.
If am I on May 1, 2015 may 21, 2015, my condition is declining. It's the bcz there is no record exists in this period.
But still he must fail, bcz between dates exist.
Can any help in this.
Thank you
Thank you all,
I solved my problem. Thanks to all who helped me.
Thank you
-
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
-
Need help with SQL/PL/SQL for Dates
Hi Experts - need help with a SQL query.
I need to insert some date fields in a table called CALENDAR_PERIOD.
Current data in CALENDAR_PERIOD table with their data types:
STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)
02/11/2014 2014 2014/02/11 SUN
03/11/2014 2014 14/03/11 MON
04/11/2014 2014 11/04/14 MAR
I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.
Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.
Can you please help me with PL/SQL block?
Really appreciate your help!
DB version:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thank you
SandyHello Sandy,
Maybe something like
INSERT INTO calendar_period (startperiod, year, period_label)
SELECT DATE '' 2014-11-04 + LEVEL
, TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))
, TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")
OF the double
CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">=>
;
((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))
Best regards
Bruno Vroman.
-
Dear all,
I have a parameter like below
11000048,11000050
I need to convert in SQL format below, please help me
"11000048","11000050"
' parameter would be so separated by commas, I need to convert in above format, if the parameter is a number say 1111111 must convert it as "1111111" in sql.
Please help me.
Thank you
You can do it
your_parameter: = "" ' | " Replace (your_parameter, ",", "",""). '"';
-
Please help me on the following sql.TABLE 1:
IS_OUTL_ID HRS_TYP_CD EFFECTIVE_DATE IS04408 ATM 5 JUNE 13 IS04408 CUSTDSP OCTOBER 5, 13 IS04408 DRVTLR NOVEMBER 5, 13 TABLE 2: This table will have future effective dates for a particular record. We have to search on the second table and take the entry into force and mark as previous record end date.
IS_OUTL_ID HRS_TYP_CD EFFECTIVE_DATE IS04408 CUSTDSP NOVEMBER 5, 13 IS04408 CUSTDSP 2 JANUARY 14 RESULT:
IS_OUTL_ID HRS_TYP_CD EFFECTIVE_DATE END_DATE IS04408 ATM 5 JUNE 13 IS04408 DRVTLR NOVEMBER 5, 13 IS04408 CUSTDSP OCTOBER 5, 13 NOVEMBER 4, 13 IS04408 CUSTDSP NOVEMBER 5, 13 1 JANUARY 14 IS04408 CUSTDSP 2 JANUARY 14 Hello
Therefore, each line of output, that you want to include end_date, based on a value between similar line, when there is one.
This looks like a job for the analytical function of LEAD, something like this:
WITH union_data AS
(
SELECT is_outl_id, hrs_typ_cd, effective_date
FROM table_1
UNION ALL
SELECT is_outl_id, hrs_typ_cd, effective_date
FROM table_2
)
SELECT is_outl_id, hrs_typ_cd, effective_date
Advance (effecive_date) OVER (PARTITION BY hrs_typ_cd
, is_outl_id - can - be
ORDER BY effective_date
) - 1 AS end_date
Of union_data
ORDER BY is_outl_id - can - be
hrs_typ_cd
effective_date
;
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Report when the above query is to give erroneous results and explain, using specific examples, how to get the correct results of data provided in these places. If you have changed the query at all, your postal code.Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002
-
Hi gurus,
I have req where I need to make the comparison between the Bill of trial ordinary bill vs. I need to get the test of the previous months and the latest current_month and 2 months of regular bills. Here are the th sample data.
Account # Invc # Start_Date end_date regular_Amoun t Trial_Amount
1233456 26470000 June 1, 2013 July 1, 2013 $19 27
1347589 26470000 August 1, 2013 current_date $45 67
1115756 26470000 may 1, 2013 July 1, 2013 $39 27This is the desired output
Account # Invc # June 2013, July, 2013 August 2013
1233456 26470000 $39 19 $ $67Any contribution is appreciated
Hello
Depending on your needs, here's a way:
WITH got_month_num AS
(
SELECT account # invc #, regular_amount, trial_amount
TRUNC (MONTHS_BETWEEN (start_date
ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),
- 3
)
)
) AS month_num
FROM table_x
WHERE the arguments start_date > = ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),-2)
AND start_date< add_months="" (trunc="" (sysdate,="" 'month'), =""> >
)
SELECT MIN (CASE WHEN month_num = 2 THEN accountt # END) AS account #.
invc #.
SUM (CASE WHEN month_num = 1 THEN regular_amount END) AS month_before_last
SUM (CASE WHEN month_num = 2 THEN regular_amount END) AS last_month
SUM (CASE WHEN month_num = 1 THEN trial_amount END) AS this_month\
OF got_month_num
GROUP BY invc #.
;
It would take to get the columns as AUG_2013 dynamic SQL alias. Your front end can help with that. In SQL * Plus, for example, you can use substitution variables.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Point where the above query is incorrect results, and explain, using specific examples, how you get the right result of data provided in these places.
Always say what version of Oracle you are using (for example, 11.2.0.2.0). In this problem, what front-end you use (for example, SQL * Plus version 10) may also be important.See the FAQ forum: https://forums.oracle.com/message/9362002
-
Help with SQL Query (Subselects)
Hello community,
IAM a new Member in this forum. The first excuse my English, my native language is German.
In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.
In this case, I have 2 tables:
Table 1:
ID; ORDER_NR; DESCRIPTION; CREATE_DATE
1; A500236; CLEAN HOUSE; 20/02/2012
2; A623555; REPAIR CAR; 10/01/2012
3; A866944; MAINTAIN EQUIPMENT; 11/02/2012
Table 2:
ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
1; A500236; A; 21/02/2012; W0010
2; A500239; F; 21/02/2012; W0010
3; A500239; S; 22/02/2012; W0027
4; A500239; R; 23/02/2012; H0034
5; A500239; U; 25/02/2012; L0099
6; A263555; A; 15/01/2012; G0009
7; A263555; C; 17/01/2012; S0039
5 V A263555; R; 18/01/2012; K0059
9; A263555; U; 19/01/2012; A0048
10; A866944; A; 13/02/2012; H0034
11; A866944; B; 13/02/2012; L0035
12; A866944; G; 17/02/2012; D0084
13; A866944; U; 23/02/2012; S0039
And the result of my query should look like this:
ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
A500236; OWN HOME; 20/02/2012; 5; 3; 1
A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3
The age of my query result should be calculated from the date of the creation of the order.
I would like to know 2 things, one is how old was the order when they reached this status, R and U.
The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column
I hope you all know what I mean and what result to expect.
Thanks for your help.
Reinhard W.Hi, Reinhard,
990524 wrote:
Hi Frank,.I thank you for your professional response and excuse my non-professional way to clarify my question.
I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.I have already noticed that the syntax SQL for Oracle differ from other DBMSS.
Yes and some features are different in different products.
Your query works perfectly, thank you.
Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.
Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.
My table contains the Date and time in a row, I forgot to mention that.
After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.
I tried something like this:
SYSDATE - MIN ( CASE WHEN t2.wo_step = 'A' THEN t2.step_date END ) AS Age_A
But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.
There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.
-
Where clause ' where 1 = 1 ' help with SQL tuning
Hello Tuning specialists,.
It is useful to use ' where 1 = 1 ' and then type all joins and conditions in the statements 'AND' of the SQL when writing SQL queries. I would like to know if it helps with the writing queirs this way SQL query performance.
Thanks in advance.
Published by: oracle_developer on October 8, 2012 10:41oracle_developer wrote:
Hello Tuning specialists,.
It is useful to use ' where 1 = 1 ' and then type all joins and joins in the statements "AND" when writing SQL queries.
I would like to know if it helps with the writing queirs this way SQL query performance.He has No. performance impact.
It is done when building dynamic SQL, so each sentence can start with AND -
with t as
(select *)
Of
(select *)
Of
(select rownum rn
of the double
connect by rownum < 100) a
where mod(a.rn,9) <>0) b
where mod(b.rn,6) <>0).
r as (select t.rn
t)
Select r.*
r
My version of oracle is: 10 G/9i
Hi all
I have the above query, now I have a scenario where I have to fill in the missing (between the smallest and largest number) numbers.
Example:
In the series of 10 consecutive numbers (with 1 interval between 2 numbers).
1
2
3
4
5
9
10
I need produce the following output:
1
2
3
4
5
6
7
8
9
10
Please help me with the sql.
Respect of
RahulHII Mac Freak Rahul,
Here's a solution:
SQL> select * from t1; COL1 ---------- 1 10 SQL> with a as (select level lev 2 from t1 3 connect by level <= (select max(col1) from t1)) 4 select a.lev 5 from a 6 minus 7 select col1 8 from t1 ; LEV ---------- 2 3 4 5 6 7 8 9 8 rows selected. SQL>
-
Help with SQL query definition
Hello
Could someone please help me with the sub condition.
On the example of the EMP table, I want a report that looks like:
Please see the application for the relevant columns and the definitions of the watch below:Manager Tot_Joiniees_Q1 Tot_Joiniees_Q2 Tot_Joiniees_Q3 Tot_Joiniees_Q4
Thank youSELECT mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END qtd, COUNT (DISTINCT ename) FROM emp GROUP BY mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END ORDER BY 1, 2
CJMSELECT mgr Manager, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '1' then 1 end) Tot_Joiniees_Q1, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '2' then 1 end) Tot_Joiniees_Q2, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '3' then 1 end) Tot_Joiniees_Q3, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '4' then 1 end) Tot_Joiniees_Q4 FROM emp GROUP BY mgr, TO_CHAR(hiredate,'Q') / MANAGER TOT_JOINIEES_Q1 TOT_JOINIEES_Q2 TOT_JOINIEES_Q3 TOT_JOINIEES_Q4 ---------- --------------- --------------- --------------- --------------- 7566 0 0 0 1 7839 0 3 0 0 7698 0 0 2 0 7788 0 1 0 0 7782 1 0 0 0 7566 0 1 0 0 7902 0 0 0 1 7698 2 0 0 0 0 0 0 1 7698 0 0 0 1 10 rows selected. SQL>
SY.
Maybe you are looking for
-
Laptop crashes when you use the CD player
A few days ago my laptop started occasionally crashing and restarting when I use the CD player. He only made 2 or 3 times but I've seen this happen with a previous (non-toshiba) laptop and it ended up happening all the time, even when not using the C
-
I've recently updated my BIOS on my laptop and it has changed some of the controls as I have to hold the Fn to set the volume and the brightness up and down. When I press the brightness button without holding the Fn, he acts as the arrows at the top
-
New arrival 11 Pro, question?
This post has 2 parts, a question and a problem: (processor core i5 4 GB, 128 GB drive) First of all, the question is the place of sessions 11 pro high-dimmable to 8.1 of Windows Pro via the propack? Secondly, I had a problem where when the device go
-
iDrac7 does not after that some has no connections
Our system has a few new servers R720 with Enterprise iDrac7. Today, I noticed that the iDrac7 IP does not respond (cannot ping, ssh, web GUI...) after three connections fail in the Web interface (I typed the wrong password). I had to unplug the powe
-
Extremely slow performance after recovery disk restore.
Machine: Dell portable computer. Router: Netgear. Cable modem: Ubee. OS: Windows 7 Professional Pro. Usage: homepage. Background: download software WiFi of Mrs Webb Page. When I tried to reboot the system has been compromised and would only boot fro