Need help SQL query
Hi all
CREATE TABLE PXX_CUST_TABLE
(NUMBER OF PERSON_ID,
DATE OF DATE_START,
DATE OF DATE_END,
ATTRIBUTE1 VARCHAR2 (30),
ATTRIBUT2 VARCHAR2 (30),
ATTRIBUT3 VARCHAR2 (30))
Insert into PXX_CUST_TABLE
(PERSON_ID, DATE_START, DATE_END, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
Values
(3619, TO_DATE (1 JULY 2015 00:00:00 ',' ' HH24:MI:SS JJ/MM/AAAA), TO_DATE (27 JULY 2015 00:00:00 ',' MM/DD/YYYY HH24:MI:SS'), ' 2015/07/12 00:00:00 ', ' 2015/07/13 00:00:00 ', ' 2015-07-14 00:00:00 ');
Insert into PXX_CUST_TABLE
(PERSON_ID, DATE_START, DATE_END, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
Values
(3619, TO_DATE (1 JULY 2015 00:00:00 ',' ' HH24:MI:SS JJ/MM/AAAA), TO_DATE (JULY 30, 2015 00:00:00 ',' MM/DD/YYYY HH24:MI:SS'), ' 2015/07/01 00:00:00 ', ' 2015/07/05 00:00:00 ', ' 2015/07/07 00:00:00 ');
Insert into PXX_CUST_TABLE
(PERSON_ID, DATE_START, DATE_END, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
Values
(3619, TO_DATE (AUGUST 1, 2015 00:00:00 ',' ' HH24:MI:SS JJ/MM/AAAA), TO_DATE (AUGUST 22, 2015 00:00:00 ',' MM/DD/YYYY HH24:MI:SS'), ' 2015/08/01 00:00:00 ', ' 2015/08/02 00:00:00 ', ' 2015-08-09 00:00:00 ')
Insert into PXX_CUST_TABLE
(PERSON_ID, DATE_START, DATE_END, ATTRIBUT1, ATTRIBUT2, ATTRIBUT3)
Values
(3619, TO_DATE (AUGUST 1, 2015 00:00:00 ',' ' HH24:MI:SS JJ/MM/AAAA), TO_DATE (AUGUST 29, 2015 00:00:00 ',' MM/DD/YYYY HH24:MI:SS'), ' 2015/08/03 00:00:00 ', ' 08/2015/04 00:00:00 ', ' 2015/08/05 00:00:00 ');
COMMIT;
SELECT * FROM PXX_CUST_TABLE
PERSON_ID DATE_START, DATE_END ATTRIBUTE1 ATTRIBUT2 ATTRIBUT3
3619 12/07/2015 27/07/2015 2015/07/01 00:00:00 00:00:13 / 07/2015 00 2015-07-14 00:00:00
3619 01/07/2015 30/07/2015 2015/07/01 00:00:00 00:00:05 / 07/2015 00 2015/07/07 00:00:00
3619 01/08/2015 22/08/2015 2015/08/01 00:00:00 00:00:02 / 08/2015 00 2015-08-09 00:00:00
3619 03/08/2015 29/08/2015 2015/08/01 00:00:00 00:00:04 / 08/2015 00 2015/08/05 00:00:00
Requirement:
You want to count the dates (attributes) only if the parameter falls between date_start and date_end.
Tested:
Select sum (attribut1, attribut2 + attribut3) Total_days
Of
(
Select
person_id, date_start, date_end,
-CHECK WITH THE CASE IF THE DATES OF THE ATTRIBUTE HAS ENTERED FALLS DATES IN THE GIVEN INTERVAL
cases where TO_DATE (SUBSTR (attribute1, 1, 10), ' YYYY/MM/DD') between TO_DATE('27-JUL-2015') AND TO_DATE('10-SEP-2015') then 1 end attribute1
case when TO_DATE (SUBSTR (attribute2, 1, 10), ' YYYY/MM/DD') between TO_DATE('27-JUL-2015') AND TO_DATE('10-SEP-2015') then 1 end attribut2
case when TO_DATE (SUBSTR (attribute3, 1, 10), ' YYYY/MM/DD') between TO_DATE('27-JUL-2015') AND TO_DATE('10-SEP-2015') then 1 end attribut3
-Intended for don't check unique records
Of
PXX_CUST_TABLE
where DATE_START BETWEEN TO_DATE('27-JUL-2015') AND TO_DATE('10-SEP-2015')
and DATE_END BETWEEN TO_DATE('27-JUL-2015') AND TO_DATE('10-SEP-2015')
)
Output:
Total_days
6
Output must be 5 as date "01/08/2015 ' is twice as much."
Please suggest.
Kind regards
Afzal.
with
pxx_cust_table as
(select 3619 person_id, to_date('07/01/2015','mm/dd/yyyy') date_start, to_date('07/27/2015','mm/dd/yyyy') date_end, to_date('2015/07/12','yyyy/mm/dd') attribute1, attribute2, to_date('2015/07/14','yyyy/mm/dd') attribut3 of all to_date('2015/07/13','yyyy/mm/dd') the double union)
Select 3619, to_date (' 07/01/2015 ',' mm/dd/yyyy'), to_date (' 07/30/2015 ',' mm/dd/yyyy'), to_date('2015/07/01','yyyy/mm/dd'), to_date('2015/07/05','yyyy/mm/dd'), to_date('2015/07/07','yyyy/mm/dd') in all the double union
Select 3619, to_date (' 01/08/2015 ',' mm/dd/yyyy'), to_date (' 08/22/2015 ',' mm/dd/yyyy'), to_date('2015/08/01','yyyy/mm/dd'), to_date('2015/08/02','yyyy/mm/dd'), to_date('2015/08/09','yyyy/mm/dd') in all the double union
Select 3619, to_date('08/01/2015','mm/dd/yyyy'), to_date('08/29/2015','mm/dd/yyyy'), to_date('2015/08/01','yyyy/mm/dd'), to_date('2015/08/04','yyyy/mm/dd'), double to_date('2015/08/05','yyyy/mm/dd')
)
Select person_id, count (distinct attribute_value) count_distinct
(select person_id, attribute_name and attribute_value
of pxx_cust_table
UNPIVOT (attribute_name attribute_value in (attribut1 1, attribut2 as 2, attribut3 3))
)
where attribute_value between date "2015-07-27' and the date ' 2015-09-10. '"
Person_id group
PERSON_ID | COUNT_DISTINCT |
---|---|
3619 | 5 |
Concerning
Etbin
Tags: Database
Similar Questions
-
Hello
I am trying to query data in my database to do the following...
' Create a query to show all members of the staff who were working on a Monday and worked for more than 86 weeks.
I did the following and it works...
SELECT employe_id, Employee_Name, Hire_Date
The EMPLOYEE
WHERE months_between(sysdate,Hire_Date) > 12 * 1.52;
The query returns all that was necessarily over 86 weeks.
What I would do, is to understand Monday in the query, but I don't know how to do this.
Could someone help?-Try this:
SELECT employe_id, Employee_Name, Hire_Date
The EMPLOYEE
WHERE months_between(sysdate,Hire_Date) > 12 * 1.52
and to_char (hire_date, 'fmDAY') = 'MONDAY ';Published by: P@K on April 14, 2009 18:26
-
Need help with query SQL Inline views + Group
Hello gurus,
I would really appreciate your time and effort on this application. I have the following data set.
Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
Please ignore '-' added for clarity
I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
Here's my query. I'm a little lost.
Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
de)
Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
of the INVOICE
Sequence_id group check_date, check_number, invoice_number, vendor_number
) A, B OF INVOICE
where A.sequence_id = B.sequence_id
Thank you
NickIt seems that this is a duplicate thread - correct me if I am wrong in this case->
Need help with query SQL Inline views + Group
Kind regards.
LOULOU.
-
Need help for query flat_file type clobdata oracle table data.
Hi Sir,
I need help to query oracle table flat file data having given clob type.
COLUMN FOR CHAR_DATA FLAT_FILEOracle Version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product PL/SQL Release 10.2.0.1.0 - Production "CORE 10.2.0.1.0 Production" TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production Source table CREATE TABLE order_details ( QUEUE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, LINE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, CHAR_DATA CLOB, OPTIMISTIC_LOCK_KEY NUMBER(20,0) )
EXPECTED RESULTS:EU,6067AT,AT10,000000402004,NexiumGERDManagementProject,Z435,,ZZ29,NIS-GOLD,AT EU,6067AT,AT10,000000402038,NIS-OEU-ARI-2007/1,Z450,,ZZ29,NIS-OEU-ARI-2007/1,AT EU,6067AT,AT10,000000402039,SymbicortNISinCOPD,Z450,,ZZ29,NIS-REU-DUM-2007/1,AT EU,6067AT,AT10,000000402040,D1443L00044SeroquelXRRuby,Z450,,ZZ29,D1443L00044,AT EU,6067AT,AT10,000000402041,NIS-GEU-DUM-2008/1,Z450,,ZZ29,NIS-GEU-DUM-2008/1,AT EU,6067AT,AT10,000000402042,SonstigeAktivitätenLCM,Z450,,ZZ29,.,AT EU,6067AT,AT10,000000402134,D1680L00002Saxagliptin,Z450,,ZZ29,D1680L00002,AT EU,6067AT,AT10,000000402199,SeroquelWaveNIS,Z450,,ZZ29,NIS-NEU-DUM-2009/1,AT EU,6067AT,AT10,000000402313,SeroquelExtra(D1443L00082),Z450,,ZZ29,D1443L00082,AT EU,6067AT,AT10,000000402517,AtlanticD5130L00006(AZD6140),Z450,,ZZ29,D5130L00006,AT EU,6067AT,AT10,000000554494,ArimidexSt.Gallen(13+2),Z142,,ZZ09,,AT EU,6067AT,AT10,000000554495,ArimidexASCO(5delegates),Z142,,ZZ09,,AT EU,6067AT,AT10,000000554496,ArimidexSanAntonio6delegates,Z142,,ZZ09,,AT EU,6067AT,AT10,000000554497,ArimidexBreastCancerSummit(13+2),Z130,,ZZ09,,AT EU,6067AT,AT10,000000554498,ArimidexEIH(15delegates),Z130,,ZZ09,,AT EU,6067AT,AT10,000000554499,ArimidexNIFA(200delegates),Z135,,ZZ09,,AT EU,6067AT,AT10,000000554500,ArimidexNIFAworkshops(8x25),Z135,,ZZ09,,AT EU,6067AT,AT10,000000554501,ArimidexPraktischeGyn.Fortbildung,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554502,ArimidexAGO,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554503,ArimidexHämato/OnkologieKongress,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554504,ARIMIDEXGYNäKOLOGENKONGRESS,Z147,,ZZ09,,AT EU,6067AT,AT10,000000554505,ArimidexChirurgenkongress,Z147,,ZZ09,,AT
AFFIRM_CODE COMPANY_CODE INTERNAL_ORDER_CODE INTERNAL_ORDER_DESC ENIGMA_ACTIVITY SUB_ACTIVITY_CODE IN_AFF_IND ORDER_TYPE EXTERNAL_ORDER COUNTRY EU 6067AT AT10 000000402004 NEXIUMGERDMANAGEMENTPROJECT Z435 NULL ZZ29 NIS-GOLD AT EU 6068AT AT11 000000402005 NEXIUMGERDMANAGEMENTPROJECT Z435 NULL ZZ29 NIS-GOLD AT
Sorry, my bad. Without database at hand, I'll try 'baby steps' (borrowed from Frank) so you don't confuse it with errors that I might add (happens far too often already, but at least you won't "swallow" as forum members think is one of the main goals of this fighter - help her learn - providing not only the proverbial fish.)
Search the Forum - your problem is one of its best sellers. Watching {message identifier: = 10694602} ("split string into" was the key word used in research) you can try something asselect table_row, level clob_row, regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) the_line from (select to_char(queue_seqnum)||':'||to_char(line_seqnum) table_row, char_data from order_details ) connect by regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) is not null and prior char_data = char_data and prior table_row = table_row and prior sys_guid() is not null
to get all the s the_lineall CLOB and after that the use of the example even to get your columns of each the_line.
Concerning
Etbin
Edited by: Etbin on 3.2.2013 09:01
.. .but I m connected to do things according to the instructions, I can't do something.
Used to happen to me too and I did as told to the but only after explaining any disadvantages, I was aware of in time. The last sentence is usually: "O.K. now be just and Don't come back with that kind of thing when it turns out that this isn't the right thing."
rp0428 post - something to remember. -
Need to SQL query to filter records by limited rows and certain condition
Hello guru (s).
I need a SQL query for help.
For an example table t1 as below, I want to find the maximum of 5 larger, but there should be no more than 2 name of the same position. The "BOLD" is the response of desire.
Name Position size
N1 P1 5
N2 P2 50
N3 P3 500
N4 P1 6
N5 P2 60
N6 P3 600
N7 P1 7
N8 P2 70
N9 P3 700
Thank you.not tested!
select name,position,size, from (select name,position,size, row_number() over (order by size desc) a_count from (select name,position,size, row_number() over (partition by position order by size desc) a_count from your_table ) where a_count <= 2 ) where a_count <= 5
Concerning
Etbin
-
Hi all
Sorry I can't speak English very well
=======================
I have a table that contains two columns
table name: total_sal
column name: hire_date
column name: salary
table syntax
create table total_sal (hire_date date
number (6.2)) of salary;
_________________________________________
Example of data in table format
hire_date | salary
01/01/2011 | 1000
01/02/2011 | 2000
01/05/2011 | 500
01/09/2011 | 400
I NEED a SQL QUERY to display the table, as in this example
OF | TO|||||||||||| TOTALSALAY
01/01/2011 | 01/02/2011 | 3000
07/05/2011 | 01/09/2011 | 900
|||||||||||||||||||||||||||||||||| 3900/* Formatted on 9/23/2011 10:14:40 AM (QP5 v5.149.1003.31008) */ WITH t AS (SELECT TO_DATE ('1/1/2011', 'mm/dd/yyyy') hire_date, 1000 salary FROM DUAL UNION SELECT TO_DATE ('2/1/2011', 'mm/dd/yyyy'), 2000 FROM DUAL UNION SELECT TO_DATE ('5/1/2011', 'mm/dd/yyyy'), 500 FROM DUAL UNION SELECT TO_DATE ('9/1/2011', 'mm/dd/yyyy'), 400 FROM DUAL) SELECT "From", "To", totalsalary FROM (SELECT hire_date "From", LEAD (hire_date) OVER (ORDER BY hire_date) "To", salary + LEAD (salary) OVER (ORDER BY hire_date) totalsalary, ROW_NUMBER () OVER (ORDER BY hire_date) rn FROM t) WHERE MOD (rn, 2) = 1 UNION ALL SELECT NULL, NULL, SUM (salary) FROM t
From To TOTALSALARY 1/1/2011 2/1/2011 3000 5/1/2011 9/1/2011 900 3900
-
Need help on query with decimal places and trailing 0
Community of Oracle I need help in the following situations:
I received the following query:
SELECT (SUM ("VALUE1") COUNT ("VALUE2"))
FROM sometable;
This returns the following results:
200
222,5
I want to display as 222.50 222,5 value so I tried ROUND(value,2) but then came to the conclusion that the tour will not show drags me 0.
So now I tried to_char(value,'9999DD00') and of course he's back 200.00 both 222.50.
Now how to make it conditional so when a number has no decimal place it shows the whole number and when it has a decimal, it shows it in the format to_char(value,'9999DD00')?
I hope I have made my situation and question correctly and I hope a solution.
P. S.
I need to appear like that since it is an average of the prices of the products
Published by: Jnijman on July 3, 2010 13:06You can use CASES and INSTR:
SQL> with t as ( -- generating sample data: 2 select 200 col from dual union 3 select 222.5 from dual 4 ) 5 -- 6 -- actual query: 7 -- 8 select col 9 , case 10 when instr(col, ',') > 0 11 then to_char(col, '999d00') 12 else to_char(col, '999' ) 13 end formatted_col 14 from t; COL FORMATT ---------- ------- 200 200 222,5 222,50
-
I need help with a simple query in an ORACLE database. I tried a lot of things that I found on the internet, but none of them worked for me.
The following query retrieves four lines:
SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3
Of asw_lab
WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM < 5
ORDER BY sampled_date DESC;
I would like to calculate a moving average of the last four values with the date of the sample of the last line.
For example, I have this result for the query above:
Value1 value2 value3
01/04/14-16:00 1 0
01/04/14 15:00 2 0
01/04/14 14:00 3 0
01/04/14 13:00 4 0
I want to extract the below my average/query calculation result:
Value1 value2 value3
01/04/14-16:00 2.5 0
Can you help me create a request to that effect?
Thank you
Maybe it's
Select max (VALUE1) VALUE1, VALUE2 avg (VALUE2), avg (VALUE3) value3
Of
(
SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3
Of asw_lab
WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM<>
)
-
Need help with query Cumulative difference
Hi all
I need help with a query and my requirement is as below
{code}
ROWNO ORDERS VALUE 1 10 900 2 11 700 3 12 500 4 13 400 {/ code}
I have need to query which will display the cumulative difference for example I value tell 10000 numbers opening
now I need for each of the lines of cumulative difference
{code}
ROWNO ORDERS DIFF
1 10 10000 - 900 = 9100
2 11 9100 - 700 = 8400
3 12 8400 - 500 = 7900
4 13 7900 - 400 = 7500
{/ code}
WITH commands LIKE (10 SELECT order_id, 900 double UNION ALL val
11. SELECT, 700 FROM dual UNION ALL
SELECT 12, 500 FROM dual UNION ALL
Select 13, 400 double)SELECT row_number() over (ORDER BY order_id ASC) AS rowno
order_id
sum (val) 10000 - OVER (ORDER BY order_id ASC) AS diff
orders/
HTH
-
Need for SQL query to get the result.
Region
Month Trx type Summary of the resolution AMERICAS -13 may Adjustments Fix EMEA -13 may Adjustments Incorrect AMERICAS -13 may Credit memo Incorrect EMEA -13 may Invoice Fix AMERICAS -13 may Credit memo Fix OFD -13 may Adjustments Fix AMERICAS -13 may Invoice Incorrect DVL -13 may Adjustments Fix DVL -13 may Adjustments Fix OFD -13 may Adjustments Fix Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?
Region Summary of the resolution Setting Credit memo Invoice Total general AMERICAS Fix 1 1 2 Incorrect 0 1 1 2 Like this?
SQL > select * from transaction_audit;
MTH TRX_TYPE REGION BOARD
-------- ------ ----------- ---------
AMERICAS-13 may SETTINGS CORRECT
EMEA-13 may INCORRECT ADJUSTMENT
AMERICAS-13 may CREDIT MEMO INCORRECT
EMEA-13 may INVOICE CORRECT
AMERICAS-13 may CREDIT MEMO CORRECT
OFD-13 may SETTINGS CORRECT
AMERICAS-13 may INVOICE INCORRECTE
LAD-13 may SETTINGS CORRECT
LAD-13 may SETTINGS CORRECT
OFD-13 may SETTINGS CORRECT10 selected lines.
SQL > select region
2, resolution_summary
3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
5, County (decode (trx_type, "BILL", trx_type)) Bill
transaction_audit 6
Group 7
8 by region
9, resolution_summary
10 Decree
11 by region
12, resolution_summary
13.REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
-------- --------- ----------- ----------- ----------
CORRECT THE AMERICAS 1 1 0
0 1 1 INCORRECT AMERICAS
EMEA CORRECT 0 0 1
INCORRECT EMEA 1 0 0
DAL ADDRESS 2 0 0
OFD CORRECT 2 0 06 selected lines.
SQL >
-
Need help with query between 2 dates
Hello
I did not SEE in a long time and need help with a simple query.
I have a table of DB access with 3 fields, name, date and number
What I want is to create a query to retrieve all the names between 2 dates
When I ask the date field, the results are showing in this formats 2013-07-12 00:00:00
Here's my query
< cfquery datasource = 'mydb' name = 'test' >
SELECT name from myTable
where edate between ' 2011-01-01 00:00:00 ' AND ' 2013-01-01 00:00:00 '
< / cfquery >
< cfoutput query = 'test' >
#name #.
< / cfoutput >
What I get is this error
ODBC = 22005 (assignment error) error code
[Microsoft] [ODBC Microsoft Access driver] Type mismatch of data in the expression of the criteria.
Don't know what I'm doing wrong here.
Please let me know.
Thank you
SELECT ename
FROM MyTable
WHERE edate BETWEEN
AND
#ename #.
-
Hi all
Required clarification of Oracle sql
Example table:
EmpNo empname mgr_id hire_date deptno salary Job
7788 SCOTT ANALYST 7566 3000 APRIL 19, 87 20
7902 7566 3000 3 DECEMBER ANALYST FORD 81 20
7934 MILLER COMMITTED JANUARY 7782 1300 23 82 10
7900 7698 DECEMBER 3, CLERK JAMES 81 950 30
7369 SMITH COMMITTED 7902 17 DECEMBER 20 800 80
7876 ADAMS 7788 1100 23 MAY CLERK 87 20
Need of ' single / one ' sql for this statement of the obligation:
There will be 2 dropdown boxes (1 - work list, 2nd - empno) in the form in which the next set of results is expected
(1) when the user selects the value of the 1st drop down box (employment) as "ANALYST", leaving the second dropdown not selected, the expected result is 2 (No. lines for this work)
(2) when the user selects the value of the 1st drop-down list (job) as "ANALYST" and the value in the 2nd drop-down box like 7902, the expected result is 1 (no lines for this job and empno)
SQLs I tried on my side (given below) gave the expected result and do please help me fix this
Select count (1) in the scott.emp where job = 'ANALYST' and (empno =: empno or empno is null);
Please help for this requirement. Any help is deeply appreciated.
Thank you
Zakari1007144 wrote:
SQLs I tried on my side (given below) gave the expected result and do please help me fix this
Select count (1) in the scott.emp where job = 'ANALYST' and (empno =: empno or empno is null);
You check "IS NULL" on EMPNO clolumn. You should check on the value passed: EMPNO. It should be
select count(1) from scott.emp where job='ANALYST' and ( empno = :empno or :empno is null ) ;
Published by: JAC on May 21, 2013 19:32
Hope that the: value of EMPLOYMENT is required... -
Have the rank as below,
name of the sum
100 A1
-A2 200
A3 300
50 A1
-A2 700
A3 80
10 A1
-A2 90
30 A3
Need to query to extract the output like this:
B1 B2
A1 + a3 (Sum) A2 (sum)
Please help me out of this...
Hello
It is difficult to understand what you want... A guess based on many assumptions:
-B1 and B2 are column headers,
-"A1 + A3" and "A2" in the 'exit' is simply to indicate that you want the sum of the amounts for the first names.-Some of the AI have all their amounts > = 0, others have their amounts<=>=>
-You want to make the sum of all positive numbers in the first column and all the negatives in the second columnSELECT SUM (GREATEST (0, t.amount)) b1
, B2 SUM (LESS (0, t.amount))
MYTABLE t
;
(I think there is only a bit of luck it's really what you want, but provide a full test case and the output that you really want and why not, try to explain / explicit rules, then we can give better help)
Best regards
Bruno Vroman.
-
Hello
I'm trying to find out who is the manager who have more number of carried forward under him of emp table
can you please help me how to find... I searched the forum and I tried some queries but does not work...
Thank you
ASP.
Hello
You need to display the results of the sample such that people who want to help you can recreate the problem and test their ideas. Do you think that people can run what you posted? You must post CREATE TABLE and INSERT statements or equivalent SB.
Once more, if you use a commonly available table, for example scott.emp, just say.
Explain how you get these results. For example, "when I say 'Manager', I mean the employee identified in the mgr column; It does not matter if job = 'MANAGER' or not. In this issue, I'm only interested in direct subordinates. For example, the KING (empno = 7839) is Manager, directly or indirectly, the other 13 lines in the table, but only 3 of these lines have mgr = 7839. There are 5 lines having mgr = 7698 (for BLAKE), so I want BLAKE rather than KING. »
Here's a way to do it:
WITH got_rnk AS
(
SELECT m.empno, m.ename, m.job - or other columns of your choice
EARL of (e.mgr) AS reportee_count
, EVALUATE () OVER (ORDER OF COUNT (*) / / DESC) AS rnk
FROM scott.emp m
LEFT OUTER JOIN scott.emp e ON e.mgr = m.empno
GROUP OF m.empno, m.ename, m.job
)
SELECT reportee_count, empno, ename
OF got_rnk
WHERE rnk = 1
;
Exit from scott.emp (in the case that is different from what you have posted);
EMPNO, ENAME, JOB REPORTEE_COUNT
---------- ---------- --------- --------------
7698 BLAKE MANAGER 5
If there be a tie for the line with the majority of direct reports, the above query will display all the contenders.
-
Need help for query joining views
Hi all
I need to run a query that joins a number of tables with multiple instances of the same view. For example, a view named MY_VALUES, is an array of key / value resembles the following:
Application_ID Attirbute_Description value
1 1 000 basic benefit
1 multiplier 1 0.5
1 Multiplier_2 1.2
1 total profit 1,115
2 1 025 basic benefit
2 multiplier 1 0,268
2 Multiplier_2 1.3
Total profit 2 1.4500
Say I want a query that selects basic earnings and a multiplier 1 for Application ID 1, as well as, other information from a table called APPLICATION that has a relationship to display pk - fk. I would do the following:
Select the application. Name, mv1.value, mv2.value
from dbo. App APPLICATION, dbo. MY_VALUES mv1, dbo. Mv2 MY_VALUES
where app.id = mv1.application_id and mv1.attribute_description = "Basic benefits"
and app.id = mv2.application and mv2.attribute_description = id 'multiplier 1'.
and app.id = 1
My actual query is similar to this. However, I have many other attributes of the notice I need to select, which requires that the view be attached to several times. After 16 these joins, the request is fine. After 17, however, the query runs always, never return a result within 45 minutes I have let it run.
Is there a better way to write such a request or an indicator of optimization that would be useful here?
Any help is greatly appreciated.
....
For this type of application, it is often best to extract multiple lines in a single request on the view and their pivot in the output.
For example
Select the application. Name
, max (CASE when mv.attribute_description = "Core service" then mv.value any other purpose) BaseBenefit
, max (CASE when mv.attribute_description = 'Multiplier 1' then mv.value any other purpose) Multiplier1
, max (CASE when mv.attribute_description = 'Multiplier 2' then mv.value any other purpose) Multiplier2
, max (CASE when mv.attribute_description = 'Multiplier 3' then mv.value end to another null) Multiplier3
from dbo. App APPLICATION, dbo. MY_VALUES mv
where app.id = mv1.application_id
and mv.attribute_description IN ('benefits of home', 'multiplier 'multiplier 'multiplier 3' 2' 1')
and app.id = 1
This runs often much better than several joins to the table for the view or the value of the attribute.
Maybe you are looking for
-
Siri, what did you do with the last update?
When I ask Siri - "Hey Siri call Cheryl", she said-"well I remember! She started doing this after the last update! My understanding is that Siri can now say Streisand correctly (who cares to say anything correctly? She cannot say a lot of things corr
-
How to stop the flashing/change pointer in Firefox 27.0?
I have a problem with the pointer constantly flashing or switch between hand tools and 'write' when it hovers over the links. I tried to restart in mode without failure, turn the circumflex, navigation, closing tabs, update Flash Player, Java Update,
-
I tried to update Firefox and repeatedly getting this message: "your computer must be restarted to complete a previous update of Firefox. Do you want to restart now? "If I click on no, nothing happens." If I click Yes, it restarts and I get the same
-
my iPhone 6 fall into the sink, what to do? :(aider s'il vous plaît)
I turn it off after that I saw a blur on the screen and let dry
-
No dialog box is displayed when you try to master cd format before burning
Or a better idea - how to copy images (film and again) on the disk.