How to create a sequence inside a select statement
I have the following query
select
t.id_trato2 as DEAL_ID, --
1 as SEQ_NO
from treats t
order by id_trato2, seq_noIt will return for example
id_trato2 seq_no
3 1
3 1
4 1
4 1
4 1
I need it to return
id_trato2 seq_no
3 1
3 2
4 1
4 2
4 3
¿how can I do this?
I need to get it as a sequence for every key (in this case id_trato2).
Results without ordering could be in this order
4
3
4
2
1
3
2
2
I need to get results in this way
4 1
3 1
4 2
2 1
1 1
3 2
2 2
2 3
if I invoke the order statement should return this
1 1
2 1
2 2
2 3
3 1
3 2
41
Similar Messages
-
How to create MIN/MAX limitations in SELECT statement ??
Hey,
I have a table which rank90 (city population ranked from 1>*) and state_abrv which has the corresponding state for each city rank.
Is there a way to select only the maximum AND minimum ranks for each state ??
I realise there is a max and min function, but i need to do it for EACH state_abrv.
An example say Los Angeles is ranked 2, San Diego is ranked 6, and San Fransico is ranked 14 (All of these citys are in california (CA)). How do i display a table which lists only Los Angeles (Highest rank) and San Fransico (lowest rank) but DOESNT list San diego ??
Thanks, you guys are helping me heaps and im starting to learn a lot more :P
Message was edited by:
user495524SQL> create table t (state varchar2(2), city varchar2(20), n number);
Table created.
SQL> insert into t values ('CA','San Francisco',14);
1 row created.
SQL> insert into t values ('CA','San Diego',6);
1 row created.
SQL> insert into t values ('CA','Los Angeles',2);
1 row created.
SQL> insert into t values ('NY','Buffalo',4);
1 row created.
SQL> insert into t values ('NY','Syracuse',7);
1 row created.
SQL> insert into t values ('NY','Mt Kisco',2);
1 row created.
SQL> insert into t values ('NY','Albany',5);
1 row created.
SQL> select * from t order by state, n desc;
ST CITY N
CA San Francisco 14
CA San Diego 6
CA Los Angeles 2
NY Syracuse 7
NY Albany 5
NY Buffalo 4
NY Mt Kisco 2
7 rows selected.
SQL> select state, city, n from
2 (
3 select t.*, min(n) over (partition by state) min_n,
4 max(n) over (partition by state) max_n from t
5 )
6 where n in (min_n, max_n) order by state, n desc;
ST CITY N
CA San Francisco 14
CA Los Angeles 2
NY Syracuse 7
NY Mt Kisco 2
SQL> -
How to create a mapping for a select statement containing DENSE_RANK( )?
Hi,
I want help with a select statement that I want to make a mapping of in OWB 11.1 g. Can anyone please tell me how is code can be incorporated in a mapping?
SELECT DISTINCT MAX (dimension_key) KEEP (DENSE_RANK FIRST ORDER BY day DESC) OVER (PARTITION BY calendar_week_name),
MAX (day) KEEP (DENSE_RANK FIRST ORDER BY DAY DESC) OVER (PARTITION BY calendar_week_name), calendar_week_end_date, calendar_week_number
FROM time_dim;I have been trying to use the Aggregator operator but I am not entirely sure how to go about it. Any help will be highly appreciated.
Thanks in advance,
Ann.Hi Ann
You can just use an EXPRESSION operator. Configure the mapping to be set based only code generation and operating mode.
You will have an expression output attribute for each one of your projected columns;
MAX (dimension_key) KEEP (DENSE_RANK FIRST ORDER BY day DESC) OVER (PARTITION BY calendar_week_name),
MAX (day) KEEP (DENSE_RANK FIRST ORDER BY DAY DESC) OVER (PARTITION BY calendar_week_name),
calendar_week_end_date,
calendar_week_number
Cheers
David -
How to Create a Sequence Number from BI Publisher Layout editor?
How to Create a Sequence Number (1,2,3,4,......,etc) from BI Publisher Layout editor
Thank you for your replay, but <?position()?> we can used it in template builder only not from BI layout editor
I found a solution in this case we can used the following query.
SELECT
ROW_NUMBER() OVER(order by item_status) as Row, -
How to create a SEQUENCE in MSSQL2005
Hi
I am also having a similar problem which opened the thread
Actually i am using a Repositery which is created in MSSQL2005.
Now i want to create a SEQUENCE similar to Oracle and populate My surrogate Key Column.
Can u tell me how to create a SEQUENCE in MSSQL2005?
Does anyone is having the sql syntax?
Thanks
GourisankarHi Gourisankar,
There is no sequence concept in MS SQL Server rather it has IDENTITY.
In MS SQL Server if you declare a column type as a Identity it will be auto increment when a new record inserts.
So in you underlying table create a column as ID and type as "Identity" and in your mapping leave that field un mapped.
Have a look and google more on "identity in ms sql server" ;)
http://www.sqlteam.com/article/autonumbering-identity-columns
http://www.craigsmullins.com/ssu_0599.htm
Thanks,
G -
How to Create Test Sequence Document in HTML using command line
How to Create Test Sequence Document in HTML using command line
I have lot of sequences and I want to create Test Sequence Documentation in HTML format using Command Line automatically, is there a way to automate this task using .bat file or using C# .NetIf you aren't able to figure out how to call a C++ DLL in .net then there may be another option. Unfortunately I don't know how to do this off the top of my head and I don't have an example.
The other option would be to change docgen.seq a little bit to the dialog doesn't display and you just hardcode the options. Then you can use a command line to call testexec.exe: http://zone.ni.com/reference/en-XX/help/370052K-01/tsfundamentals/infotopics/startup_opt/
Hope this helps,
jigg
CTA, CLA
teststandhelp.com
~Will work for kudos and/or BBQ~ -
How to create a sequence DDL in a procedure
Hello,
i have a simple question but i dont find a solution here.
How to create a sequence DDL in a procedure ?
Thank 'sUse Native Dynamic Sql. Look at the EXECUTE IMMEDIATE command.
declare
begin
execute immediate 'create sequence xx_seq ';
end;
/Of course you need explicit permission to create a sequence. NOT through a ROLE. -
How to create Option Boxes IN A SELECTION SCREEN
How to create Option Boxes IN A SELECTION SCREEN.
Thanks!Hi Rajesh,
The following explanation gives clear picture of what is mean of check box and radio button with coding.....................
<b>CHECK BOX :</b>
AS CHECKBOX [USER-COMMAND fcode]
Effect:
This addition specifies that the input field in the first position of the selection screen is displayed as a checkbox, with the corresponding description next to it on the right. The checkbox is selected if the value of para is "X" or r "x". Otherwise, it is not selected.
The parameter must be created with the type c and length 1. An explicit length len is not permitted. If the addition TYPE is used, this can only be followed by the generic type c or a non-generic data type of type c and length 1.
The addition USER-COMMAND can be used to assign a function code fcode to the parameter. The function code fcode must be directly specified and may have a maximum length of 20 characters. To evaluate the function code, an interface work area of the structure SSCRFIELDS from the ABAP Dictionary must be declared using the statement TABLES. When the user selects the checkbox on the selection screen, the runtime environment triggers the event AT SELECTION-SCREEN and transfers the function code fcode to the component ucomm of the interface work area sscrfields.
Notes
If the TYPE addition is used to make a reference to a data type in the ABAP Dictionary of type CHAR and length 1, and for which t the valid values in the domain are defined as "X" and " ", the parameter is automatically displayed as a checkbox on the selection screen.
If the addition USER-COMMAND is specified without the addition AS CHECKBOX, and the parameter is of type c with length 1, it is also displayed as a checkbox.
The addition USER-COMMAND can, for example, be used for screen modifications with the addition MODIF ID (see example).
<b>Coding :</b>
PARAMETERS show_all AS CHECKBOX USER-COMMAND flag.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p1(10) TYPE c,
p2(10) TYPE c,
p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: p4(10) TYPE c MODIF ID bl2,
p5(10) TYPE c MODIF ID bl2,
p6(10) TYPE c MODIF ID bl2.
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF show_all <> 'X' AND
screen-group1 = 'BL2'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
<b>RADIO BUTTON COMMAND :</b>
RADIOBUTTON GROUP group [USER-COMMAND fcode]
Effect:
This addition specifies that the input field is displayed as a radio button in the first position on the selection screen, and the output field is displayed next to it on the right. The radio button is selected if the value of para is "X" or "x". Otherwise, it is not selected.
group is used to define the radio button group for the parameter. The name group is entered directly as a character string with a maximum of 4 characters. Within a selection screen, there must be a minimum of two parameters in the same radio button group. There cannot be more than one radio button group with the same name in one program, even if they are defined in different selection screens.
The parameter must be specified with the type c and length 1. Explicit length specification using len is not permitted. If the addition TYPE is used, it can only be followed by the generic type c or a non-generic data type of type c and length 1.
In a radio button group, only one parameter can be defined with the addition DEFAULT, and the specified value must be "X". By default, the first parameter in a radio button group is set to the value "X", and the rest are set to " ".
The addition USER-COMMAND can be used to assign a function code fcode to the first parameter in a radio button group. The function code fcode must be specified directly, and have a maximum length of 20 characters. To evaluate the function code, an interface work area of the structure SSCRFIELDS from the ABAP Dictionary must be declared using the statement TABLES. When the user selects any radio button of the radio button group on the selection screen, the runtime environment triggers the event AT SELECTION-SCREEN and transfers the function code fcode to the component ucomm of the interface work area sscrfields.
Note:
It is recommended to define the radio buttons of a radio button group directly underneath each other. If the selection screen also contains other elements, it is recommended to define each radio button group within a block surrounded by a frame.
<b>CODING :</b>
tables : mkpf,mseg,ekko.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER : P_WERKS LIKE MARC-WERKS MODIF ID S1,
c as checkbox.
SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN NO INTERVALS MODIF ID S2.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-004.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS : R1 RADIOBUTTON GROUP G1 DEFAULT 'X' USER-COMMAND UC1.
SELECTION-SCREEN COMMENT 5(20) TEXT-002 FOR FIELD R1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS : R2 RADIOBUTTON GROUP G1.
SELECTION-SCREEN COMMENT 5(20) TEXT-003 FOR FIELD R2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
write :/ p_werks,
/ s_ebeln.
AT SELECTION-SCREEN OUTPUT .
LOOP AT SCREEN .
IF R1 EQ 'X' AND SCREEN-GROUP1 EQ 'S2'.
SCREEN-INPUT = 0.
SCREEN-REQUIRED = 1.
clear s_ebeln[].
clear p_werks.
MODIFY SCREEN.
ENDIF.
IF R2 EQ 'X' AND SCREEN-GROUP1 EQ 'S1'.
SCREEN-INPUT = 0.
SCREEN-REQUIRED = 1.
clear s_ebeln[].
clear p_werks.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
Let me knwo if any doubts.
<b>Reward with points if it helpful</b>
Regards,
Vijay -
Create a view using a select statement
Hi
I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
I am new to oracle so any help will do.
ThanksHi
I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
I am new to oracle so any help will do.
Thanks -
How to compile the hint to force selection statement to use index
Hello expert,
will you please tell me how to compile the hint to force selection statement to use index?
Many Thanks,Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
SQL> explain plan for
2 select * from emp
3 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 546 | 3 (0)| 00:00:01 |
8 rows selected.
SQL> explain plan for
2 select /*+ index(emp,pk_emp) */ *
3 from emp
4 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 4170700152
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 546 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 00:00:01 |
9 rows selected.
SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
SY. -
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
How to create a sequence for an particular item in my apex form
Hi friends,
I created an database application, of a form with a report, and it is working fine...
But in my form, i have a requirement....The below are the existing fields in my form
issue no
created by
start date
status
priority
due date
Among these fields in my form i need to create a 'Sequence' for my field "issue no",
So that whenever i opened the form the 'issue number' must generate automatically like 1 for the first time, 2 for the second time and so on..
For that i created a sequence
CREATE SEQUENCE "ORDERS_SEQ"
MINVALUE 1
MAXVALUE 999999999999999999999999999
INCREMENT BY 1
START WITH 1000
NOCACHE
NOCYCLE;
But for validation where i need to write the sequence query for the particular item 'issue no'....i dont have any idea of where to write the validation query for the sequence..
please tell where i need to write in step wise manner..please help me friends...
As the below is my validated sequence query for item 'issue no'
'select seq.issue_id.nextval into issue_no'
This is my above validation query whether the query that i mentioned is right..if not let me know the validation query..
And also i need where to apply this validation query in steps..
Thanks in advance
Regards,
Harry...Harry,
Rik is on the right track. Here is a sample insert trigger: Would need to substitute you sequence ORDERS_SEQ with my sequence las_log_seq, how you define or use timestamps is up to you.
DROP TRIGGER LASDEV.BINS1_LAS_LOG_TBL;
CREATE OR REPLACE TRIGGER LASDEV."BINS1_LAS_LOG_TBL"
BEFORE INSERT
ON las_log_tbl
FOR EACH ROW
BEGIN
-- Description: Insert log_seq, creation_dt, creation_id,
-- lst_updt_dt and lst_updt_id.
-- Maintenance:
-- Date Actor Action
-- ==== ===== ======
-- 07-Sep-2010 J. Wells Create.
:new.creation_id := nvl( v( 'app_user' ), user );
:new.creation_dt := SYSDATE;
:new.lst_updt_dt := :new.creation_dt;
:new.lst_updt_id := :new.creation_id;
SELECT las_log_seq.NEXTVAL
INTO :new.las_log_seq
FROM DUAL;
END bins1_las_log_tbl;
/Heff -
How to create a Sequence;
Hi All,
I have a master block and child block;
I need to create sequence number in child block like 1 2 3 4
Line #
1....date1.....12......
2....date2.....xxx....
3....xxx........xxx....
4..........
When i create new customer and its detail it should start with new sequence
and some one query the records and open it then this should continue the sequence.
Thx.
Message was edited by:
J.HarshaJan, I have created the multi records it is fine,
This is about how to get the sequence numbers,
Lets say some one open one record and it have 5 detail records.
if he is in second detail record and try to insert a new record i want to show
Line id 6
I was trying with
SELECT nvl(MAX(LINE_PERIOD)+1,0) INTO l_LINE_PERIOD FROM XX_RATE_LINE RL
WHERE RL.CUSTOMER_ID=:MSF_V.CUSTOMER_ID;
if l_line_period>4 then -- we gave default 4 records
bk_id := Find_Block('MSF_LINE');
--last_record;
:line_period := Get_Block_Property( bk_id, MAX_RECORDS_FETCHED)+1;
--CURRENT_RECORD);
--MAX_RECORDS_FETCHED
end if;
CURRENT_RECORD is good if some one navigating properly always into the last record.
Message was edited by:
J.Harsha -
How to create a sequence in oracle forms6i
Oracle forms 6i
Hai All
I am working in leave application entry so i need to create a sequence for giving a unique number for each entry
Pls tell me the steps how to created and how to call the sequence from database
Thanks in Advance
Srikkanth.mHi,
Create sequence <sequence_name>
Start with <number>
increment by <number>
in database
eg:- create sequence test_seq
start with 1
increment by 1;
in forms
you can assign value in pre-insert trigger
Declare
cursor cur_seq is
select test_seq.nextval from dual;
begin
open cur_seq;
fetch cur_seq into :item_key ; /* :item_key give name of ur primary key field*/
close cur_seq;
end; -
How to create Table Popins inside a table using Java Webdynpro
Hi All,
I am working on a Java Webdynpro project and one of our requirements is to create Table popins inside the Table. I need to popin data beneath the row based on a value selected from the DropDown Box which is one of the column in the Table.
Also, I need to display vertical scrollbar instead of Table Footer to scroll thru the table rows. Any ideas.........
I would appreciate if you can let me know how can I do this. I am working on the 7.0 version of Java Webdynpro.
Thanks for your time and consideration!
Regards,
MadhaviHi,
Please refer the following link:
Re: Table popins
step by step procudure to create table popin on lead select.
thanks & regards,
Manoj
Edited by: Manoj Kumar on Apr 1, 2008 10:17 AM
Maybe you are looking for
-
Hello Experts , Need help to disable a check box via Scripting . Appreciate your help .. Regards, Tayi
-
I'm setting up my new iPhone 4 and it won't accept my apple ID
I'm setting up my new iPhone 4 and it won't accept my apple ID. I just created it and everytime I enter it in the setup screen it says Can't Create Apple ID: Account Limit Reached.
-
I got a white Nano the day they came out and I love it. But the little screen is getting so scratched up that I'm afraid in a year or so it will be blurry. I don't have anything else in my front left pocket where I keep it, except the ear buds. I did
-
Dear All... I am very new in oracle discoverer. I am thinking about using Oracle Business Intelligence 10.1.3.4.1 with my oracle database. I have some queries.. 1) Does Oracle Business Intelligence 10.1.3.4.1 works with out Oracle Apps ? (I am instal
-
The Edit Reconciliation Policy action was not valid
I�m trying to �Edit Reconciliation Policy� in IDM 7.1 from Resources -> List Resources and the drop down menu �Resource Type Actions� but It is giving error message *�The 'Edit Reconciliation Policy' action was not valid for one or more of the select