Please help for my query?
I have a data table following:
Field: ID VALUE MONTH
Data: 111 2 4
111 6 2
222 3 3
222 7 6
333 5 3
333 4 5
333 4 1
I want to write a query using GROUP BY (ID), SUM(value) AND MAX(Month) that return results following:
111 8 4
222 10 6
333 13 5
But I don't know to take it. Please help me to resolve this require
Thanks in advance!
Edited by: user11807715 on Aug 19, 2009 8:25 PM
Why wouldn't it just be
SELECT is, sum(value), max(month)
FROM your_table
GROUP BY idJustin
Similar Messages
-
Please Help for the Query
Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
date ticker indicator
03/13/2008 3IINFOTECH -8
03/18/2008 3IINFOTECH -4
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3
as such :-
date ticker indicator
03/13/2008 3IINFOTECH -8
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3
Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
So I want the data
date ticker indicator
03/13/2008 3IINFOTECH -8
03/25/2008 3IINFOTECH -5
03/27/2008 3IINFOTECH -3SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
Tabla creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
1 fila creada.
SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
1 fila creada.
SQL> COMMIT;
Validación terminada.
SQL>
SQL> SELECT FECHA, INDICA
2 FROM BORRAME
3 WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
4 ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
FECHA
INDICA
13/03/08
3IINFOTECH -8
25/03/08
3IINFOTECH -5
27/03/08
3IINFOTECH -3
-
SQL experts please help for a query
I have following table1.
What query can give the result as given below, SQL experts please help on this.
TABLE1
Event DATETIME
in 2/JAN/2010
out 2/JAN/2010
in 13/JAN/2010
out 13/JAN/2010
in 5/JAN/2010
out 5/JAN/2010
RESULT REQUIRED FROM THE SQL QUERY
COL1_IN COL2_OUT
2/JAN/2010 2/JAN/2010
13/JAN/2010 13/JAN/2010
5/JAN/2010 5/JAN/2010I tried to help, but this puzzles me.
Why is this not returning pre-selected set of rows, why it's doing some merge join cartezian ?
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> select * from table1;
EVENT DATETIME
in 2/JAN/2010
out 2/JAN/2010
in 13/JAN/2010
out 13/JAN/2010
in 5/JAN/2010
out 5/JAN/2010
6 rows selected.
SQL> explain plan for
2 with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
Explained.
SQL> set wrap off
SQL> set linesize 200
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 185132177
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 9 | 288 | 8 (0)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 9 | 288 | 8 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL | TABLE1 | 3 | 48 | 3 (0)| 00:00:01 |
| 3 | BUFFER SORT | | 3 | 48 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | TABLE1 | 3 | 48 | 2 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
2 - filter("EVENT"='in')
4 - filter("EVENT"='out')
Note
- dynamic sampling used for this statement
21 rows selected.
SQL> with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
COL1_IN COL2_OUT
2/JAN/2010 2/JAN/2010
2/JAN/2010 13/JAN/2010
2/JAN/2010 5/JAN/2010
13/JAN/2010 2/JAN/2010
13/JAN/2010 13/JAN/2010
13/JAN/2010 5/JAN/2010
5/JAN/2010 2/JAN/2010
5/JAN/2010 13/JAN/2010
5/JAN/2010 5/JAN/2010
9 rows selected.
SQL> -
Please help for my iphone 4 unlock
please help for my iphone 4 unlock
Apple store said my iPhone 4 had an LCD issue and that is why slide to unlock is frozen. My warranty ran out so it would cost approx. $150 to repair it he said. Time for a new phone but not sure I want another iPhone now.
-
Hello. Please help. for unknow reasons, I am not getting any of my mail on anything, nothing on my iphone, my outlook or even when I log into icloud online>???
any one else having troble??
please help
I need my mailHello, DragonStudios.
Thank you for visiting Apple Support Communities.
Here are a couple troubleshooting resources I would recommend when experiencing issues with iCloud Mail.
iCloud: Troubleshooting iCloud Mail
http://support.apple.com/kb/TS4002
iCloud: Account troubleshooting
http://support.apple.com/kb/TS3988
Cheers,
Jason H. -
hello all!
please, help me again.
we have a foreign key discrepancy and my task is to create a view which will show the 3 aspects.
Let's we have 3 schemas: A - good (which means that i will compare WITH A, source)
B and C are bad (which mean that I will checking this schemas).
So, i need to obtain:
1) FK that DO NOT exist in B&C and do exist in A
2) FK that DO exist in bad schemas (B&C) but DO NOT exist in good schema (A)
3) FK's that exist in both (A&B, A&C) schemas on the SAME TABLE, have THE SAME CONSTRAINT_NAME but are on the DIFFERENT columns.
the first and second I seem to be done through the
select CONSTRAINT_NAME, TABLE_NAME, STATUS from dba_constraints where owner='PRIV_MD' and CONSTRAINT_TYPE='R' and CONSTRAINT_NAME
2 NOT IN (select CONSTRAINT_NAME from dba_constraints where owner ='MSA_MD'); (to get the second task we just reversing owners in query and subquery)
query. but the third one is really pain in my back. i have a query:
SELECT a.column_name, b.column_name FROM dba_cons_columns a, dba_cons_columns b, dba_constraints c, dba_constraints d
WHERE c.CONSTRAINT_TYPE='R'
AND a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
AND a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
AND b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
AND a.owner = 'PRIV_MD' AND b.owner = 'MSA_MD';
which runs hours and returns million of rows with the two columns with the same names... but if i'm adding
AND a.column_name != a.column_name (i'm not sure it's a correct syntax)
line it returns "no rows selected"
please, help me obtain it, i'm fighting already the second day..
(please, don't be angry, i'm just learning and this is my first task on my work...)This is basically just a UNION ALL (the constraint columns from both schemas)
MINUS what exists in both (the INTERSECTion)
I made it a little more complicated so you could see in which schema the column is used. You could use exactly the same approach for your questions 1 and 2 also.
SELECT * FROM
(SELECT a.column_name,c.constraint_name,'salive' schema_containing
FROM dba_cons_columns a
INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
UNION ALL
select b.column_name,d.constraint_name,'satest'
FROM dba_cons_columns b
INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') u
WHERE NOT EXISTS
(SELECT *
FROM
(SELECT a.column_name,c.constraint_name
FROM dba_cons_columns a
INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
INTERSECT
select b.column_name,d.constraint_name
FROM dba_cons_columns b
INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') i
WHERE u.column_name = i.column_name and u.constraint_name = i.constraint_name) -
Please help with the query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
VALUES
(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
:REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
:SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
:HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
:CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
:ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
:STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youYou cannot use (and do not want to in this case) the BULK COLLECT.
create table for_testing
the_id number not null primary key,
some_data number
declare
l_return_value for_testing.the_id%type;
begin
4
insert into for_testing
the_id,
some_data
values
1,
5
returning the_id into l_return_value;
dbms_output.put_line('the return values is ' || l_return_value);
end;
20 /
the return values is 1
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable . -
Help for a query to add columns
Hi,
I need for a query where I should add each TableC value as an additional column.
Please suggest...
I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
Considering Id of TableA.
Sample data
TableA :
ID NAME TABLENAME ETYPE
23 Name1 TABLE NAMEA Etype A
TableB :
ID A_ID RTYPE RNAME
26 23 RTYPEA RNAMEA
61 23 RTYPEB RNAMEB
TableC :
ID B_ID COMPNAME CONC
83 26 Comp Name AA 1.5
46 26 Comp Name BB 2.2
101 61 Comp Name CC 4.2
Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
Output required: Put each TABLEC value as an additional column
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME TableC_1_CONC TableC_2_COMPNAME TableC_2_CONC
Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2 so on..
Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL
Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
Output:
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
TableC_1_CONCvalue value value value valueHi,
Welcome to the forum!
Do you want the data from TableC presented
(1) in one column, or
(2) in several columns (a different column of results for each row in the original TableC)?
(1) Is called String Aggregation and is easier than (2).
The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
Ignoring TableA for now, you could get what you want by saying
SELECT b.rtype
, STRAGG ( c.compname
|| ' '
|| c.conc
) AS c_data
FROM TableB b
JOIN TableC c ON b.id = c.b_id
GROUP BY b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
(a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
(b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
The two scripts below contain basic information on pivots.
This first script is similar to what you would do for case (a):
-- How to Pivot a Result Set (Display Rows as Columns)
-- For Oracle 10, and earlier
-- Actually, this works in any version of Oracle, but the
-- "SELECT ... PIVOT" feature introduced in Oracle 11
-- is better. (See Query 2, below.)
-- This example uses the scott.emp table.
-- Given a query that produces three rows for every department,
-- how can we show the same data in a query that has one row
-- per department, and three separate columns?
-- For example, the query below counts the number of employess
-- in each departent that have one of three given jobs:
PROMPT ========== 0. Simple COUNT ... GROUP BY ==========
SELECT deptno
, job
, COUNT (*) AS cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
, job;
Output:
DEPTNO JOB CNT
20 CLERK 2
20 MANAGER 1
30 CLERK 1
30 MANAGER 1
10 CLERK 1
10 MANAGER 1
20 ANALYST 2
PROMPT ========== 1. Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno;
-- Output:
DEPTNO ANALYST_CNT CLERK_CNT MANAGER_CNT
30 0 1 1
20 2 2 1
10 0 1 1
-- Explanation
(1) Decide what you want the output to look like.
(E.g. "I want a row for each department,
and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
(2) Get a result set where every row identifies which row
and which column of the output will be affected.
In the example above, deptno identifies the row, and
job identifies the column.
Both deptno and job happened to be in the original table.
That is not always the case; sometimes you have to
compute new columns based on the original data.
(3) Use aggregate functions and CASE (or DECODE) to produce
the pivoted columns.
The CASE statement will pick
only the rows of raw data that belong in the column.
If each cell in the output corresponds to (at most)
one row of input, then you can use MIN or MAX as the
aggregate function.
If many rows of input can be reflected in a single cell
of output, then use SUM, COUNT, AVG, STRAGG, or some other
aggregate function.
GROUP BY the column that identifies rows.
PROMPT ========== 2. Oracle 11 PIVOT ==========
WITH e AS
( -- Begin sub-query e to SELECT columns for PIVOT
SELECT deptno
, job
FROM scott.emp
) -- End sub-query e to SELECT columns for PIVOT
SELECT *
FROM e
PIVOT ( COUNT (*)
FOR job IN ( 'ANALYST' AS analyst
, 'CLERK' AS clerk
, 'MANAGER' AS manager
NOTES ON ORACLE 11 PIVOT:
(1) You must use a sub-query to select the raw columns.
An in-line view (not shown) is an example of a sub-query.
(2) GROUP BY is implied for all columns not in the PIVOT clause.
(3) Column aliases are optional.
If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
{code}
The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
{code}
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus.
(This can be easily adapted to PL/SQL or other tools.)
PROMPT ========== 0. Basic Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
ORDER BY deptno
PROMPT ========== 1. Dynamic Pivot ==========
-- ***** Start of dynamic_pivot.sql *****
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT DISTINCT
', COUNT (CASE WHEN job = '''
|| job
|| ''' ' AS txt1
, 'THEN 1 END) AS '
|| job
|| '_CNT' AS txt2
FROM scott.emp
ORDER BY txt1;
SPOOL OFF
-- Restore SQL*Plus features suppressed earlier
SET FEEDBACK ON
SET PAGESIZE 50
SPOOL p:\sql\cookbook\dynamic_pivot.lst
SELECT deptno
@@dynamic_pivot_subscript
FROM scott.emp
GROUP BY deptno
ORDER BY deptno
SPOOL OFF
-- ***** End of dynamic_pivot.sql *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one. If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one. That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
{code} -
Please help me in Query result.
Hello Friends..
Need some help .
I have refreshed one workbook for one sales document , and it is showing me all the data.
Could you please tell me how can i check all the key figure value , because in Query properties it is restricted to 0.
Means , if all the Key figure value are 0 , then it will not show that Row in Report .
I want to see the result of 0 value as well with out changing Query properties.
Please help me and advice me , how can i do this.
RegardsHi Jain,
Without changing the query properties it will not be possible to view all values.
If you want to view with changing the properties of query.
Youcan do the following steps
select each attributes right click >restrict->bring back the restricted value->and execute the query.
all the rows will be dispalyed
Hope this helps
Cheers
Sunil -
Hello everyone,
Could anyone please help me to figure out this query......
I have following tables and data
create table code_ref (
ref_id number,
type_id number,
name varchar2(50));
insert into code_ref values(100, 1, 'Part One');
insert into code_ref values(101, 1, 'Part Two');
insert into code_ref values(120, 1, 'Part Three');
insert into code_ref values(125, 1, 'Part Four');
commit;
create table product(
product_id number,
name varchar2(50));
insert into product values(1, 'Product 1');
insert into product values(2, 'Product 2');
insert into product values(3, 'Product 3');
commit;
create table product_parts(
product_id number,
part_id number,
part_desc varchar2(50));
insert into product_parts values(1, 100, 'Product 1, Part 1');
insert into product_parts values(1, 120, 'Product 1, Part 3');
insert into product_parts values(2, 100, 'Product 1, Part 1');
insert into product_parts values(2, 101, 'Product 1, Part 2');
insert into product_parts values(2, 120, 'Product 1, Part 3');
insert into product_parts values(3, 101, 'Product 1, Part 2');
commit;I am able to get this output:
select *
from (select product_id, part_id from product_parts group by product_id, part_id)
pivot (count(part_id) for part_id in(100 "Part One", 101 "Part Two", 120 "Part Three", 125 "Part Four"))
order by product_id;
PRODUCT_ID Part One Part Two Part Three Part Four
1 1 0 1 0
2 1 1 1 0
3 0 1 0 0However, since the new PART can be added later on, and must be included in above output, how to write this SELECT. I tried "for part_id in (select......)", it did not work :-(
Thanks in advance!!!Hi,
Sorry, the exact number of columns produced by any query has to be hard-coded into the query itself.
user489948 wrote:
... However, since the new PART can be added later on, and must be included in above output, how to write this SELECT. I tried "for part_id in (select......)", it did not work :-(Using a sub-query there only works if you're getting XML output. The result set will have a single XMLTYPE column, which may contain any number of elements.
See the following thread for some other work-arounds:
Re: Report count and sum from many rows into many columns -
select * from testme;
NAME VAL
A 1
A 2
A 3
B 1
B 2
B 3
C 1
C 2
I want to get the maximum of name and the maximum of corresponding name's value.
ie., the answer should be
Name VAL
C 2
Please help me with the query.
ThnxSQL> create table testme
2 as
3 select 'A' name, 1 val from dual union all
4 select 'A', 2 from dual union all
5 select 'A', 3 from dual union all
6 select 'B', 1 from dual union all
7 select 'B', 2 from dual union all
8 select 'B', 3 from dual union all
9 select 'C', 1 from dual union all
10 select 'C', 2 from dual
11 /
Tabel is aangemaakt.
SQL> select max(name) name
2 , max(val) keep (dense_rank last order by name) val
3 from testme
4 /
NAME VAL
C 2Regards,
Rob. -
Please help for User defined extension functions
the tutorial given for extension functions doesn't work as well as our new functions
even though i follow all the given steps and see the functions in my user defined extension functions tab in xslt map.
all the target nodes that use the extension function disappear in the resulted target xml.
please help.have you compiled your java file and uploaded the jar file(containg the .class file and the Manifest.MF file) in the <OC4J_HOME>\j2ee\home\applib directory and then restarted the server??
-
Dear all,
I have data in a table with 3 columns.
Tabke name---test & columns are ....
Proeductioncode varchar2(5);
revisionno varchar2(3);
dateadopted char(8);
SELECT PRODUCTIONCODE,
REVISIONNO,
dateadopted
FROM test
where
productioncode ='CI50E';
output should be
productioncode revisionno dateadopted
CI50E 004 20110125
CI50E 001 20101104
CI50E 003 20110320
CI50E 002 20101214
My requirement is
I wanna display records which are dateadopted is > sysdate and
one record which is less than sysdate, which is the max(<sysdate)..
from the data above, the output should be
CI50E 003 20110320
CI50E 004 20110125
Please help me get this output. we need to write it in a select query.Sorry I don't have a database available to test - missed to join by productioncode :( grouping by revisionno caused more than one row being returned :(
No need to send data. I added a data providing subquery. Will take shot when I get to the database, but I might not be able to post from the office
with
/* generating test data */
test as
(select 'CI50E' productioncode,'004' revisionno,'20110125' dateadopted from dual union all /* 003 if increasing by date */
select 'CI50E','001','20101104' from dual union all
select 'CI50E','003','20110320' from dual union all /* 004 if increasing by date */
select 'CI50E','002','20101214' from dual union all
select 'XI50Y','001','20110220' from dual union all
select 'XI50Y','002','20110220' from dual union all
select 'XI50Y','003','20110304' from dual
/* end of test data generation */
SELECT productioncode,revisionno,dateadopted
FROM (select productioncode,revisionno,dateadopted
from test a
where (dateadopted > to_char(sysdate,'yyyymmdd'))
or dateadopted = (select max(dateadopted)
from test
where productioncode = a.productioncode
and dateadopted < to_char(sysdate,'yyyymmdd')
ORDER BY PRODUCTIONCODERegards
Etbin
Edited by: Etbin on 20.2.2011 21:58
did some alignment
Edited by: Etbin on 21.2.2011 7:39
missing right parenthesis added, group by clause removed since there is just a single product
Edited by: Etbin on 21.2.2011 7:52
some more data edit -
Hi All....
Required help for one more query.
I have a table with data like this:
Cust_id Transaction_no
111 1
111 2
111 3
111 4
111 5
111 6
222 7
222 8
333 9
333 10
333 11
333 12
I wrote the following query :
select cust_id, ntile(3) over (order by cust_id) "Bucket" from trans_detls
The output is like this :
Cust_id Bucket
111 1
111 1
111 1
111 1
111 2
111 2
222 2
222 2
333 3
333 3
333 3
333 3
The problem is that I dont want the cust_id to overlap in buckets. That is one cust_id should be present in only one bucket.
Is this possible?
Thanks in advance.
AmeyaOr Something like..
SQL> select * from test;
ID NO
111 1
111 2
111 3
111 4
111 5
111 6
222 7
222 8
333 9
333 10
333 11
333 12
12 rows selected.
SQL> select id, ntile(3) over (order by rn) "Bucket"
2 from(
3 select id,row_number() over(partition by id order by no) rn
4 from test);
ID Bucket
111 1
222 1
333 1
111 1
222 2
333 2
111 2
333 2
111 3
333 3
111 3
111 3
12 rows selected. -
Please help for using perform in SAP script
As subject.
My sap script code as below:
/: PERFORM GET_CHAMT_DATE IN PROGRAM ZRAP004
/:USING &SPELL-WORD&
/:CHANGING &SPELL-WORD&
/:ENDPERFORM
My program ZRAP004 code as below:
FORM get_chamt_date USING u_iword TYPE spell-word
CHANGING u_oword TYPE spell-word.
CONCATENATE u_iword '元整'(t01) INTO u_oword.
endform.
This form is for check printing.
It's by standard function 'F110' to excute check printing.
But when i finished this transaction. System return error message as below:
<b>This routine contains 2 formal parameters, but the current call
contains 4 actual parameters.</b>
Please help. Thanks a lot!!Hiii
PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK
/:USING &EKKO-EBELN&
/:CHANGING &CDECENT&
/:ENDPERFORM
The report :
REPORT zkrpmm_perform_z1medruck .
DATA : BEGIN OF it_input_table OCCURS 10.
INCLUDE STRUCTURE itcsy.
DATA : END OF it_input_table.
déclaration de la table output_table contenant les
variables exportées
DATA : BEGIN OF it_output_table OCCURS 0.
INCLUDE STRUCTURE itcsy.
DATA : END OF it_output_table.
DATA : w_ebeln LIKE ekko-ebeln,
w_vbeln LIKE vbak-vbeln,
w_zcdffa LIKE vbak-zcdffa.
FORM CDE_CENT
FORM cde_cent TABLES input output.
it_input_table[] = input[].
it_output_table[] = output[].
READ TABLE it_input_table INDEX 1.
MOVE it_input_table-value TO w_ebeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_ebeln
IMPORTING
output = w_ebeln.
SELECT SINGLE zcdffa FROM ekko
INTO w_zcdffa
WHERE ebeln = w_ebeln.
it_output_table-name = 'CDECENT'.
MOVE w_zcdffa TO it_output_table-value.
MODIFY it_output_table INDEX 1.
output[] = it_output_table[].
ENDFORM.
Maybe you are looking for
-
Does 6509 switch support CDP bypass feature when interface configured with IEEE 802.1X?
hi, guys we are deploying CISCO video endpoints (SX 20) for out customers, as the access switch is 6509 which version is 12.2(33)SXJ5 following is the configuration on the interface, but the endpoints can not pass through the authentication,
-
My old telephone number is stored in Facetime. How do I change?
I recently recieved a Mac. I also have a knew phone, same number. My old phone (that husband is using) is stored and I can't use FACEtime correctly. Help...
-
Unable to Insert Adobe Edge Animate files into Dreamweaver CS6!
I have just tried the new Insert Edge Media feature in the new Cloud version of Dreamweaver CS6, but I can't get it to work!! I have the option, but all the files in the Edge folder are unhighlighted (grey'd out) and I am unable to select anything Ed
-
How long is standard, manufacturer's warranty on new Laserjet P1102w printer?
I just bought an HP LaserJet P1102w (in the United States). It is working well, but I'm wondering how long the warrantee is? 30 days? 90? A year? Just so I know how long to keep the receipt. This question was solved. View Solution.
-
I have done something to my computer and not it won't take my password and it's locked so I can't make changes. I can't install my downloads. Is there any other option other than disc restore?