How to write query with low cost

hi
i want to write a query of low cost for the following scenario.
in a table
if a person got a salary >=10000 he is in grade A
if a person got salary >=7000 he is in grade B
if a person got salary >=5000 he is in grade C
if a person got salary >=3000 he is in grade D
else grade E.

use CASE
case when salary >= 10000 then 'A'
       when salary >= 7000 then 'B'
       else 'E'
end as grade
     

Similar Messages

  • QUESTION:  HOW TO WRITE QUERY  WITH MANY TO MANY RELATIONSHIPS

    Could someone help me out here?
    I was sitting here looking at some tables ie table_name and synonyms and wondering.
    If a table can belong to many synonyms and a synonym can belong to many tables how would one write a query where I would like to know which tables belong to each synonym or on the other hand which synonym belongs to what tables?
    Would I try to develop an outside join for this, a corrolated query or a query with a subquery or would there be another format that would work better?
    What would be the best method of attack on this?
    Thanks for your thoughts on this.
    al

    Actually, the relationship is not many to many. A table can have many synonyms, but a synonym within a namespace (i.e. a PUBLIC synonym, or a private synonym created by a user) can only point to one table. The xxx_synonmys tables already contain the information about the table_name and table_owner.
    John

  • How to write ! , . with virtual keyboard?

    how to write ! , . with virtual keyboard?
    Thanks!

    What do you mean by virtual keyboard?I guess he means the "Robot" class, and the answer is
    to "press" shift, then press the 1 key, then release
    the 1 key then release shift.Are you basing that on the steering the mouse question?
    I guess.

  • How to write query for this in TopLink ?

    I am doing a simple search in jsp where the search will the based on the choices chosen by user.
    I had given 3 check boxes for those choices.
    The problem is, query will be based on the choice or choices chosed by the user.
    How to write query for this in TopLink ?
    Thanks in Advance..
    Jayaganesh

    Try below solution, it is NOT best solution but might work:
    Declare @Questions TABLE (QuestionID INT, QuestionText Varchar(100))
    INSERT INTO @Questions
    VALUES (1, 'Comment'), (2, 'Score')
    DECLARE @Answers TABLE (authkey INT, QuestionID INT, questiontext VARCHAR(100), answertext VARCHAR(100))
    INSERT INTO @Answers
    VALUES (101, 1, 'comment', 'hi!!'), (101, 2, 'score', '4'), (102, 1, 'comment', 'excellent'), (102, 2, 'score', '5'), (103, 2, 'score', '6'), (104, 2, 'score', '8')
    SELECT
    A.AuthKey
    ,Q.QuestionID
    ,Q.QuestionText
    ,A.AnswerText
    FROM
    @Questions Q
    INNER JOIN @Answers A ON Q.QuestionID = A.QuestionID
    UNION
    SELECT
    A.AuthKey
    ,Q.QuestionID
    ,Q.QuestionText
    ,Null
    FROM
    @Questions Q
    CROSS JOIN @Answers A
    WHERE
    NOT EXISTS (SELECT 1 FROM @Answers SubQry WHERE SubQry.AuthKey = A.AuthKey AND SubQry.QuestionID = Q.QuestionID)
    Output
    AuthKey | QuestionID
    | QuestionText
    | AnswerText
    101 | 1 | Comment | hi!!
    101 | 2 | Score | 4
    102 | 1 | Comment | excellent
    102 | 2 | Score | 5
    103 | 1 | Comment | NULL
    103 | 2 | Score | 6
    104 | 1 | Comment | NULL
    104 | 2 | Score | 8
    Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

  • How to write strings with an underline on the TOP-OF-PAGE of ALV

    How to write strings with an underline on the TOP-OF-PAGE of ALV

    if u r using classes and methods it can be done
    but if u r using normal fms and then u have to use HTML_TOP_OF_PAGE but the drawback for this it cannot be printed when the report is printed .

  • How to write query to list all the employees of deptno 20

    Hi ,
    I am new to Oracle...Recently I got job.... Could you please help me....
    How to write a query for
    1) List all the Clerks of Deptno 20 and
    2) List the emps along with their exp and whose daily salary is more than 100rs

    its not wrong that you ask , but this is basic question and my suggestion is to start reading some manual specially since you got job , Read oracle documentation gogole what you want if you didn't find any answer post here and we will help you .
    Check this link
    http://www.oracle-dba-online.com/sql/oracle_sql_tutorial.htm
    http://www.w3schools.com/sql/default.asp
    http://www.java2s.com/Tutorial/Oracle/CatalogOracle.htm
    And you will find more & more .. create your own vmware oracle provide with learning database called XE (express edition) test it and hope this information is useful for you

  • How to write XML with attributes to a table in Oracle?

    I tried to find solutions over the internet. Some of the stuff I looked at:https://forums.oracle.com/thread/2182669 http://www.club-oracle.com/forums/how-to-insert-data-from-xml-to-table-t2845/
    In all these cases, the solution considers XML structure with only nodes and child nodes but not attributes. In fact, one of the solutions suggests transforming the XML into a canonical form with only nodes w/o attributes.
    This is a sample of xml structure I am working with:
    Sample XML
    <rep type="P" title="P List"> <as> <a id="3" /> <a id="4" /> </as> </rep>
    I am working with oracle client 11.2 and SQL developer
    My question is: how to write XML data into a table with attributes also as column values, beside the nodes?

    My question is: how to write XML data into a table with attributes also as column values, beside the nodes
    The question you should be asking is : "how do I access attributes in the XPath language?"
    and the answer to that is easily found in any XPath tutorial you may find over the Internet, it is not related to Oracle in particular.
    Short answer : you use an "attribute::" axis before the attribute name, or more commonly a "@", e.g. @type, @id etc.
    Using the method described in the first link, something like this will extract the root attributes :
    SELECT x.*
    FROM XMLTable(
           '/rep'
           passing <xmltype variable/column goes here>
           columns type  varchar2(1)  path '@type'
                 , title varchar2(30) path '@title'
    ) x ;
    For deeper levels, use additional XMLTable calls as described in the mentioned post.

  • Re-write query with ANY operator

    Hi,
    How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
    SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
    And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
    1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
    2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
    3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
    thanks
    rincy

    please post your question in separate SQL and PL/SQL section this is FORMS section

  • UDF-how to write query

    Hi
    I have UDF on form. How to make query, to choose values values from OITM in U_MODEL where U_BRAND = definite value

    Hi,
    1.Use same query (as attached in screen shot) and assign to U_model as per attached below.
    2. To get list, just Press shift + F2 at U_model
    Thanks & Regards,
    Nagarajan

  • How to republish stream with lower quality

    Hey guys, I was wondering is there a way that I can receive stream on my broadcast server and then republish that stream with lower quality on the same broadcast server. I was reading server side API reference but I couldnt find anything like that.
    Only thing I found is to use %i in FMLE Stream field and then broadcast same stream with different bitrates, but can I take live stream that is being broadcasted and republish it with lower quality/bitrate on the server side somehow?
    Or there is another way to achieve this?
    I am running FMS 4.5 and I am using FMLE to broadcast video to the server.
    Thank you for your answers.

    FMS can't transcode streams. What you could do is use FFMPEG to pull the stream from FMS and publish a transcoded stream back into FMS.
    Alternately, you could use Wowza Media Server and their transcoder plugin (fairly easy), or Wowza and Xuggler (requires a fair amount of programming)

  • How to write query group by  time(minutes)

    Hi,
    i am writting query like this.
    select host_id,pd_user, pdUserUtil,
    timestamp from
    (select host_id,pd_user,
    avg(pd_cpu) pdUserUtil,
    to_Char(PD_REPORTED_TIMESTAMP,'yyyy-mm-dd hh:MI') timestamp
    from sp_process_detail_current SP
    where exists (select * from
    sp_process_detail_current
    having
    max(PD_REPORTED_TIMESTAMP)-sp.PD_REPORTED_TIMESTAMP<5/1440)
    group by pd_user,host_Id,to_Char(PD_REPORTED_TIMESTAMP,'yyyy-mm-dd hh:MI'))
    where host_id='DSCP04881' and pd_user='TOMCAT'
    TIMESTAMP PD_USER
    2006-06-30 08:07 TOMCAT
    2006-06-30 08:08 TOMCAT
    2006-06-30 08:10 TOMCAT
    BUT WHILE ACCESSING IN JAVA
    java.lang.NumberFormatException: For input string: "30:08:07"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.

    Question: What datatype in Java are you using as placeholder for the timestamp column?
    It's only taking the "2006-06-" part.
    Post here the java code (an exceprt of course), though I feel there's better forums for this subject.

  • How to write query

    Hi,
    I need expert advice.
    on daily basis we are updating meter reading ( meter reading is nothing but "meter number / unit / date".
    Let say there are 10 apartment  and each apartment has separate meter.
    i need to write query get missing meter reading on a specific date.
    Thanks

    Unit Master
    401
    402
    403
    404
    Daily Meter Reading
    date               unit     meter
    01-01-01          1     401
    01-01-01          1     402
    01-01-01          1     404  ( on 1st of jan user update the meter reading but if you notice unit number 403 is missing)
    02-01-01          1     401
    02-01-01                402 ( on 2nd of jan user update the meter reading but if you notice this time 402 is meter unit is missing)
    02-01-01          1     403
    02-01-01          1     404
    03-01-01                  401
    03-01-01          1     402
    03-01-01          1     403 ( on 3rd of jan user update the meter reading but if you notice this time meter unit is missing for 401 and 404 is unit is missing)
    We want the following output
    if user run report on 1st of jan system should return value of 403 unit number
    if user run report on 2nd of jan then system should return value of 402 unit number
    if user run report on 3rd of jan then system should return value of 401/404 unit number
    Hope this help to get my expected answer.

  • Sql query runing slow with lower cost

    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ?
    Any idea why second query is runing fast after commenting few columns in select and group by clause.
    Query 1
    SELECT PH.CTRL_NBR, PD.SEQ_NBR,PH.CNTRY,PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNIT_VOL,
    IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNITVOL,
    IM.UNITWT,
    IM.PACK_QTY
    Query 2 .
    SELECT PH.CTRL_NBR,
    PD.SEQ_NBR,
    PH.CNTRY,
    PH.SHIP_DATE,
    PHI.WAVE_NBR,
    PD.ID,
    PD.QTY,
    -- IM.PACK_QTY,
    -- IM.UNIT_VOL,
    -- IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    -- IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    --IM.PACK_QTY,
    --IM.UNITVOL,
    --IM.UNITWT,
    --IM.PACK_QTY
    Edited by: oradba11 on Sep 6, 2012 2:11 PM
    Edited by: oradba11 on Sep 6, 2012 2:12 PM

    oradba11 wrote:
    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ? <snip>
    This doesn't address your question, but let me suggest that for your own sanity you start brining some formatting to your sql. And for the sanity of those on this forum of whom you expect assistance, you preserve that formatting through the use of the code tags (see the FAQ for details).
    I've done the first one for you, as an example of what I mean
    SELECT
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,     PHI.WAVE_NBR
    ,     PD.ID
    ,     PD.QTY
    ,     IM.PACK_QTY
    ,     IM.UNIT_VOL
    ,     IM.PACK_QTY
    ,     MAX(CD.PACK_QTY) AS CASE_QTY
    ,     IM.UNIT_WT
    FROM
         HDR PH
    ,     HDR_INTRNL PHI
    ,     DTL PD
    ,     HDR CH
    ,     CASEDTL CD
    ,     IMASTER IM
    WHERE
         PH.CTRL_NBR = PHI.CTRL_NBR
       AND  PD.CTRL_NBR = PH.CTRL_NBR
       AND  PD.QTY > 0
       AND  SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
       AND  CD.CASENBR = CH.CASENBR
       AND  CH.STAT_CODE BETWEEN '10' AND '90'
       AND  IM.ID = PD.ID
       AND  PHI.WAVE_NBR='EL57893'
    GROUP BY
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,      PHI.WAVE_NBR
    ,      PD.ID
    ,      PD.QTY
    ,      IM.PACK_QTY
    ,     IM.UNITVOL
    ,     IM.UNITWT
    ,     IM.PACK_QTY

  • How to write query...? can be done with cross tab...?

    Hi,
    I have one table like
    PlaceId PlaceName
    1 A
    2 B
    1 C
    1 D
    3 E
    4 F
    4 G
    3 H
    I want output like
    PlaceId PlaceName
    1 A,C,D
    2 B
    3 E,H
    4 F,G
    please help on this. using SQL instead of PL/SQL
    thanks in advance

    Use User Defined String Aggregate Functions
    Please see this link
    http://www.adp-gmbh.ch/ora/sql/user_def_agg.html
    Also the links
    Oracle9i Data Cartridge Developer's Guide and Examples from Asktom
    1)
    http://www.lc.leidenuniv.nl/awcourse/oracle/appdev.920/a96595/dci11agg.htm
    2)
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:5269744394385
    3)
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

  • How to write query for shuttle box

    hi
    i am creating an shuttle box on my input page and need to write a query to display the selected columns in the shuttle box..
    i have created the shuttle bottle and gave the static values in it , i can view my values but cannot understand how to give the condition which allows me to display the data
    only for selected columns ...
    Please Help

    thank you for reply..
    I am completely new to oracle apex...i think here there is a prcodure to get default values into the right side box, my question is , how do i write a query for all the items in the left side box columns when selected to right side, the data has to be displayed only for those columns...
    i am looking for syntax of the query ...
    For eg there 4 columns on the left hand side of the shuttle box
    job_id
    cluster_id
    cluster_code
    cluster_name
    and i select just job_id and cluster_id to right hand side , i need to display data associated with only these 2 columns...
    Please Help
    Edited by: user12855387 on Apr 20, 2010 11:08 AM

Maybe you are looking for