Query that returns number 1 - Add additional columns based on percentages

I have a query that returns a large number.  The return value will always be a single field (a column, a line, a single value).

I need to have also three other columns in the return of this request: one that returns a number that is 50% of the original number, one that returns a number that is 75% of the original number, and one that is double the original number.  How is that possible?  If anyone can point me to examples, it would be a great help.  I got the results mixed by searching, so I'm not sure good practices.

Thank you for the input in advance.

Hello

Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

Explain, using specific examples, how you get these results from these data.

If you show what you want to do using commonly available tables, like those of the scott schema, then you don't need to display the sample data; just results and explanations.

Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum: Re: 2. How can I ask a question on the forums?

I'm not sure that understand the question.

If x is a number, then

.50 * x is 50% of this number,

.75 * x is 75% of that number, and

2 * x is to double this figure.

You can get them all in the same query, if you want to.  For example:

SELECT ename

sal

.50 * sal AS p_50

.75 * sal AS p_75

2 * sal AS dbl

FROM scott.emp;

Output:

ENAME SAL P_50 P_75 DBL

---------- ---------- ---------- ---------- ----------

SMITH, 800, 400, 600, 1600

1600 800 1200 3200 ALLEN

1250 625 WARD 937,5 2500

JONES 2975 1487.5 2231,25 5950

1250 625 MARTIN 937,5 2500

2850 1425 BLAKE 2137,5 5700

2450 1225 CLARK 1837,5 4900

3000 1500 2250 6000 SCOTT

KING 5000 2500 3750 10000

1500 750 1125 3000 TURNER

1100 550 825 2200 ADAMS

JAMES 950 475 712,5 1900

FORD 3000 1500 2250 6000

1300 650 975 2600 MILLER

Is that what you ask?

Tags: Database

Similar Questions

  • How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    I have a table whose columns with values such as

    MINNEAŸPOLIS and ¿VV ¿A

    Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.

    Please help to write a SQL SELECT with Regexp_like query or any other option.

    Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.

    SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

  • I need a query that returns the average amount of characters from text colum in MS SQL.

    I need a query that returns the average amount of characters from text colum in MS SQL.

    Could someone show me how?

    Sorting, I need of the

    DATALENGTH

    function

  • SQL QUERY THAT RETURNS THE PL/SQL

    Hello

    I'm putting in 4.2 below apex

    DECLARE

    date of frdate: =: P22_FROMDATE;

    date date: =: P22_TODATE;

    l_date1 varchar2 (11): = to_char(frdate,'dd-mon-yyyy');

    l_date2 varchar2 (11): = to_char(todate,'dd-mon-yyyy');

    v_sql varchar2 (32000);

    v_Name varchar2 (4000): = months_name (frdate, todate);

    char (1) of the v1: = q "[']";

    number of lbr1 (6): =: P22_FROMBRANCH;

    number of LBR2 (6): =: P22_TOBRANCH;

    number of M1 (6): = 11;

    Start

    v_sql: ='SELECT * FROM (SELECT LBRCODE, PRDACCTID, MN, AVGX FROM (SELECT LBRCODE, PRDACCTID, MN, SUM (BALL) BALL, COUNT (MN) DAYS, ROUND (SUM (BAL) count (MN), 2) AVGX ';))

    v_sql: = v_sql | "FROM (SELECT LBRCODE, PRDACCTID, TO_CHAR (BALDATE,'|)) CHR (39) | ' MM' | CHR (39) |') ' | ' ||'|| CHR (39) | » _'|| CHR (39) |' | ' || «TO_CHAR (BALDATE,'|)» CHR (39) | ' AAAA '. CHR (39) |') MN, BALL ';

    V_SQL: = V_SQL | "(SELECT Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE, T_OST_NEW (Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE) BALL ';

    V_SQL: = V_SQL | "FROM (select TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') baldate FROM DUAL Union all the ';

    V_SQL: = V_SQL |' select (TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') + level) double baldate ';

    V_SQL: = V_SQL |' connect by level < = (TO_DATE('||) Chr (39) | l_date2 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') -TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' Dd-mon-yyyy ' | CHR (39) |')) ) Q1,';

    V_SQL: = V_SQL | "(SELECT LBRCODE,'|) ' (rpad (prdcd, 8,'|)) V1 ||'' || v1 |') || LTRIM (rpad('|| v1 ||) » x'|| V1 | «, 25, » || v1 | » 0' || v1||'),'|| v1 | » x'|| v1 |')) prdacctid OF D009021 WHERE the LBRCODE between ' | : P22_FROMBRANCH |' and ' | : P22_TOBRANCH | "AND moduleinfo =' | TO_NUMBER(:P22_SELECTLIST);

    V_SQL: = V_SQL |') ((Q2)) GROUP BY LBRCODE, PRDACCTID, MN))';

    V_SQL: = V_SQL | "PIVOT (MAX (AVGX) (MN) IN (';))

    V_SQL: = V_SQL | V_NAME;

    V_SQL: = V_SQL |')) ORDER OF LBRCODE, PRDACCTID ';

    RETURN V_SQL;

    END;

    I created all the elements of the required page

    I get the error message like missing expression

    to test, I created a function to return the query, it works very well know to return a query that gives me desired report

    am I missing something?

    Help, please

    HEMU wrote:

    Hello Sir

    Sorry to bother you again

    I tried to use «function that returns colon-delimited topics»

    and I got following error

    unable to determine query headings: ORA-06550: line 1, column 138: PLS-00103: Encountered the symbol ";" when expecting one of the following:  . ( ) , * % & = - + < / > at in is mod remainder not rem =>  <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset The symbol ")" was substituted for ";" to continue.
    
    failed to parse SQL query:
    

    can take you a look at page901 once again please and a function named months_namex

    is it feasible that I'm looking for?

    The immediate cause of this error is simply incorrect report headings function call syntax:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy')

    This should be:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy'));

    However there is no months_namex function defined in the workspace.

  • R12 payment process Request Status Report add additional columns to the XML data.

    In 11i, we had modified the preliminary report of payment to include additional columns (distributions of invoice). R12, this report is obsolete and Oracle introduced a new report 'Payment process Request Status Report'. This query uses BI Publisher to generate the release of the final report. I can't edit the template for the output XML to the report has not
    contains data for distribution invoice account. We need to know how we can modify the XML data to include additional columns.

    For the disbursement of funds (payment instructions file) process, Oracle provides extensibility IBY_FD_EXTRACT_EXT_PUB package to build the custom XML element structure that can be added to the extracted XML payment generated by the Oracle payments. Do we have something similar to this report? Are there other options available?

    Thank you

    Hello

    The same "IBY_FD_EXTRACT_EXT_PUB" package also works for the payment request process status report. Please add the logic to get the distribution data in this package, and you'll see the new XML tags in this report also.

    I hope this helps.
    Serge

  • How to perform an addition of column values in an insert query that would insert in the 3rd column, and the values how to insert into another table.

    I have two tables (2) RESULT TAB (1)

    CREATE TABLE TAB

    (

    NUMBER OF SNO

    A NUMBER,

    B THE NUMBER.

    NUMBER OF THE SUM

    );

    CREATE AN ARRAY OF RESULT

    (

    NUMBER OF SNO

    NUMBER OF THE SUM

    )

    my doubt is:

    (1) I want to insert a table TAB, my question is how to insert a column to the SUM using the column A AND B... Here im adding two values of the column and store result in the AMOUNT column.

    SNO   A  SUM           

    1 100 150 250

    2 300 100 400

    I want to like this, it is possible with single insert query?


    (2) at the time of the insertion TAB of values that SNO, and the values of table TAB $ insert in the table of RESULTS... is it possible these two inserts at the same time?

    in fact, im using another this table.fro TAB and easy to understand I write like that, please solve this problem

    First, you post in the wrong forum as this one is only for Oracle's SQL developer tool. So you might ask your question in the general forum of SQL.

    Second, you might solve your problems with bind variable:

    Insert tab

    (sno, a, b, sum)

    values

    (: SNO,: A: B: A + B :))

    You should not use sum as column name because it is a reserved word.

    More you cannot insert into two different tables with a single SQL, but you can use PL/SQL to do this:

    Start

    insert into tab values (: SNO,: A: B: A + B :);)

    insert into result values (: SNO,: A + B :);)

    end;

    If you meet sno from a sequence, you could do something like this:

    Start

    insert into values tab (seq_sno.nextval,:,: B,: A +: B) return sno in: SNO.

    insert into result values (: SNO,: A + B :);)

    end;

    Hope that helps,

    dhalek

  • Help turn the query that returns single return system

    Hello, I have two tables, readings, and values. Values have a foreign key to the readings.
    create table readings 
    (
    id number primary key,
    point number,
    datereading date
    );
    
    create table reading_values
    (
    id number primary key,
    counter_nr number,
    point number,
    reading_id number,
    datereading date,
    CONSTRAINT fk_reading
    FOREIGN KEY (reading_id)
    REFERENCES readings (id)
    );
    The point and datereadings columns have the same value of related rows.
    insert into readings values (1, 1234, to_date('20100622 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (1, 0, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row1
    insert into reading_values values (2, 1, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row2
    
    insert into readings values (2, 1234, to_date('20100623 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (3, 0, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row3
    insert into reading_values values (4, 1, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row4
    
    insert into readings values (3, 1111, to_date('20100621 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (5, 0, 1111, 3, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row5
    Now I have the procedure which the entry: p_point and p_date.
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < p_date and point = p_point
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    so I want the previous reading_values (in time based on p_date) for a certain point p_date. I hope this makes sense?
    Example:
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < to_date('20100624 12:12', 'yyyymmdd HH24:MI') and point = 1234
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    
    returns row 3 and 4
    Now, what I want to do, is replace p_point and p_date with two collections. For example: p_points = [1234, 1111] p_dates = [20100622 15:12, 20100624 12:12]
    Here, I want to have the previous reading_values by point = 1234 and datereading < 20100622 order 15:12 by datereading (where rownum < = 1).

    and also reading_values by point = 1111 and datereading < 20100624 order 12:12 by datereading (where rownum < = 1).

    This should return line1, line2 and row5...

    So far I came up with this. But I can't be sure that it is correct. And the performance seems to be horrible (cost 88, 13 recursive calls, 155 becomes uniform) for a query with 2 entry points and 2 dates compared to the original to just a single point query and the date of entry (cost 13, 1 recursive call and gets 14 coherent).
    Select rv.* from (SELECT r.id
          FROM    Readings r, 
          (select rownum rn1, t1.id from table1 t1 order by id) t1, -- input parameter1 (point collection)
          (select rownum rn2, t2.date_now from table1 t2 order by id) t2  -- input parameter 2 (date collection)
          WHERE  r.point = t1.id
              AND     r.datereading = (SELECT  max(r2.datereading)
              FROM   Readings r2
                WHERE   r2.point = t1.id
                AND     r2.datereading < t2.date_now AND rn1 = rn2)
        ) r, Reading_Values rv where r.id= rv.reading_id;
    code for creating table 1 that I used instead of collections of entry:
    create table table1
    (
     id number not null primary key,
     date_now date not null
    );
    insert into table1 values (1234, to_date('20100622 15:12', 'yyyymmdd HH24:MI'));
    insert into table1 values (1111, to_date('20100624 12:12', 'yyyymmdd HH24:MI'));
    Hope someone can help me on my way :) Please ask if something is unclear or strange! Thank you!

    Published by: KarlTrumstedt on 23-jun-2010 06:20

    Try this

    SELECT RV.ID, RV.COUNTER_NR, RV.POINT, RV.READING_ID, RV.DATEREADING
    FROM (
        SELECT (    SELECT LAST_VALUE(RE.ID) OVER
                         (PARTITION BY RE.POINT ORDER BY RE.DATEREADING)
                    FROM READINGS RE
                    WHERE RE.DATEREADING < T1.DATE_NOW AND RE.POINT = T1.ID
                ) ID,
                T1.ID POINT,
                T1.DATE_NOW
        FROM TABLE1 T1
    ) X
    JOIN READING_VALUES RV
    ON (X.ID = RV.READING_ID AND X.POINT = RV.POINT)
    ;
    
  • Query that returns only certain fields in Java

    Currently I use a filter that identifies certain keys, then get all the keys and get a unique value of each object. The rest of the object is important enough. I've seen references to the passage on the ability to do it, using CohQL, but I can't run Java.

    Basically, I want to do: "select the"Cache"box where key ="asdf '" I just want back the specific 'field' rather than the entire object. How can I do this?

    Thank you.

    Hi user13279246,

    You can do this by using the ReducerAggregator. Your code would look like:

    Filter filter = QueryHelper.createFilter(...);
    ValueExtractor extractor = new ReflectionExtractor("isReadOnly");
    Map mapResult = cache.aggregate(filter, new ReducerAggregator(extractor));
    

    The mapResult will be indexed by the actual cache keys, but the values will be extracted Boolean property.

    If you need to return a number of "columns", you would use the MultiExtractor instead. In this case, each value in the returned map would be a list of corresponding extracted properties.

    Kind regards
    Gene

    Published by: ggleyzer on February 15, 2011 16:41

  • Oracle BPM 12.2.1 workspace how to add additional columns to the DB table tasklist

    Hi all

    I need to add some required columns to the table from the list of tasks (for example, activity and status of the activity referred to in the task line), I decompiled adflibTaskListTaskflow.jar and found a class named TaskModel.class in this package: oracle.bpel.worklistapp.tasklist.beans.model, if decompile you this class, you can see that at the table from the list of tasks, data are expressed here by using ITaskQueryService now how more columns may add other tables or is there another easier solution?

    Hi Hadi,

    You can add columns to your table of task list in the workspace by changing the current view, or even create a new (more and icons in pencil). The situation of activity is available in the list of columns.

    You can also add columns to the list view based on flexfields tasks that you create.

    If you manually change the adflibTaskListTaskflow.jar you can have problems in the future given that libraries can change between versions and of course are not recommended to do.

    I have add columns to the list of tasks, and at that time here, we have created a list of custom task based on BPM Middleware. If you follow this method, you will have complete freedom to show what you want.

  • Doubt with query that returns unnecessary reocrds

    Hello
    I use under query to retrieve security descending titles in a database:

    Select master sre1.security_id,
    sre2. Clone SECURITY_ID, sa1. Addr STREET_ADDR1
    Of
    SAM_REAL_ESTATE sre1, SAM_REAL_ESTATE sre2, sam_address sa1, sa2 sam_address
    where
    sre1. ADDRESS_ID = sa1. ADDRESS_ID and sre2. ADDRESS_ID = sa2. ADDRESS_ID
    and sre1.security_id < sre2. SECURITY_ID
    and trim (nvl (upper (sa1. STREET_ADDR1), 'Null')) = trim (nvl (upper (sa2. STREET_ADDR1), 'Null'))
    and in sre1.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
    and in sre2.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
    order by 1, 2;


    which returns results as below:

    MASTER CLONE ADDR
    20306795 20530359 Waverley
    20306795 21943331 Waverley
    * 20530359 21943331 Waverley *.
    175459876 175460770 temple
    175459876 175460893 temple
    * 175460770 temple 175460893 *.

    Now, I do not want the selected records in bold as the safety of clone is coming security master while only the less registration by different address should enter into main list and the rest of his security should come clone

    Please suggest

    Thank you
    Deepak

    NOT TESTED

    select min(master) master,clone,addr
      from (select sre1.security_id master,
                   sre2.SECURITY_ID clone,
                   sa1.STREET_ADDR1 addr
              from SAM_REAL_ESTATE sre1,
                   SAM_REAL_ESTATE sre2,
                   sam_address sa1,
                   sam_address sa2
             where sre1.ADDRESS_ID = sa1.ADDRESS_ID
               and sre2.ADDRESS_ID = sa2.ADDRESS_ID
               and sre1.security_id < sre2.SECURITY_ID
               and trim(nvl(upper(sa1.STREET_ADDR1),'Null')) = trim(nvl(upper(sa2.STREET_ADDR1),'Null'))
               and sre1.security_id in(175459876,175460893,175460770,20530359,21943331,20306795)
               and sre2.security_id in(175459876,175460893,175460770,20530359,21943331,20306795)
             order by sre2.SECURITY_ID,upper(sa1.STREET_ADDR1),sre1.security_id
           )
     group by clone,addr
     order by 1,2
    

    Concerning

    Etbin

    It is not a Top - N query

    Edited by: Etbin the 13.8.2009 12:00

  • Query that returns several generic criteria using as and in

    Hi there, try to do something like this:

    Select * from tablename
    Where columnname as 5% ' or as 8% ' or like 12% '

    without the help OR... so in this big:

    Select * from tablename
    Where columnname like IN (5% ", 8%, 12%" ")

    In MS Sql, I can do something like this:

    SELECT * from tablename t
    Where exists (select val FROM dbo.fn_String_To_Table (25, 05', '', 0))
    ATA columname WHERE AS val + '%')

    Where dbo.fn_String_To_Table converts the array of strings in a table.

    Any suggestions?

    Thank you very much.

    Samir says:

    where the comma-delimited string variable?

    Use your imagination :):

    select  *
      from  tablename t
      where regexp_like(t.column_name,'^(' || replace(starts_with_scv,',','|') || ')')
    / 
    

    SY.

  • Add additional columns to a select * statement?

    is there a way to do something like:
    select *, table_A.value*.25 from table_A
    Thank you

    Edited by: nwill on January 14, 2010 08:14

    '25' is a constant? If I understand you right, you can do this:

    select table_A.*, 25 from table_A;
    
  • Looping on a method that returns a query

    Hello

    I have a method that returns a query, I convey in this method, an identification number, the query uses in where clause. Now I have another query that returns a list of identification numbers that I have to loop through the appellant the first method and passing in the ID number, for example

    methodA

    Browse the methodA results
    Call methodB passing methodA.ID
    results of methodB
    close the loop

    now, the problem I have is that methodB returns a query and I want to be able to return the results of methodB as a unique query structure. I don't know how many times I will do a loop through the results of methodA, maybe twice, he could by ten times. Thus, the results of calling methodB could be very large.
    How can I add methodB results in a single query structure?

    I finally had to create a monster query with joins in about three tables, but it works.

  • Additional column in a table


    Hi all

    I would like to add an additional column in a table, and it must have the values Valiid or Invallid.

    I mean that I need to have the list of values for the invallid or column showing which.

    Please let me know, how to get there.

    Thank you

    Kumar.

    Hi Kumar,

    user624202 wrote:

    Hi all

    I would like to add an additional column in a table, and it must have the values Valiid or Invallid.

    I mean that I need to have the list of values for the invallid or column showing which.

    Please let me know, how to get there.

    Thank you

    Kumar.

    Assuming that you want to add the column to capture valid or not valid and store it in the database, if this is the case.

    1 Add this column that will contain the values for valid and invalid in the table to your query in a table

    Here I added the status column that will keep VALID and INVALID in the database

    select
    "EMPNO",
    "ENAME",
    "JOB",
    "MGR",
    "STATUS"
    from EMP
    

    2. go to the attributes of the region-> column to change the STATE of

    Goto column attributes

    Display as-> list of selection (named LOV)

    Named LOV-> select your Lov

    Attributes of tabular form Goto

    Owner of the reference Table-> select the scheme name

    Reference Table name-> the name of the table

    Name of column reference-> give the name of column

    Hope this helpe you,

    Kind regards

    Jitendra

Maybe you are looking for