transformation of query using joins

My current query works perfectly.

SELECT so.* FROM shipping_order so, WHERE (so.submitter = 20) OR (so.requestor_id IN (SELECT poc.objid FROM point_of_contact WHERE poc.ain = 20 poc)) OR so.objid IN (SELECT ats.shipping_order_id from ac_to_so ats WHERE (ats.access_control_id IN (objid selectac.) Of access_control ac WHERE ac.ain = 20 GOLD ac.group IN ("buyers", "managers")))

But when I try to create it using the join instructions examples I do not get the correct results or no results indeed.

Here's the query with joins.

SELECT so.* FROM shipping_order so INNER JOIN point_of_contact ON (so.requestor_id = poc.objid AND poc.ain = 20) INNER JOIN ac_to_so ats WE (so.objid = ats.shipping_order_id) INNER JOIN access_control ac WE (ats.access_control_id = ac.objid AND (ac.group ("buyers", "managers") IN GOLD ac.ain = 20)) WHERE (so.submitter = 20)

Any ideas on what I am doing wrong. I tried both outer joins and received no results either.

TIA.

Published by: user9522282 on March 11, 2009 06:27 fixed typo
select s.*
  from shipping_order s
  left outer
  join ac_to_so a
    on (s.objid = a.shipping_order_id)
  left outer
  join access_control ac
    on (a.access_control_id = ac.objid)
  join point_of_contact poc
    on (poc.objid = s.requestor_id)
 where s.submitter = 20
    or poc.ain = 20
    or ac.ain = 20
    or ac.user_group in ('buyers', 'managers')

Tags: Database

Similar Questions

  • query using the JOIN

    Hello


    my appearance of the table structure:

    Column names:

    Road
    BU
    sub_bu
    report_order
    sub_bu_order
    q1py

    My query is:

    Select road, bu, Sub_bu, report_order, sub_bu_order, q1py, case
    When sub_bu = 'ISS' then (select q1py from STG where 'a.sub_bu =' ESS and a.rhead = b.rhead)
    When sub_bu = "TS" then (select q1py from STG where 'a.sub_bu =' Services and a.rhead = b.rhead)
    When sub_bu = "SW" then (select q1py from STG where a.sub_bu = 'SW' and a.rhead = b.rhead)
    otherwise NULL end as q1py_bu,
    case
    When sub_bu = 'ISS' then (select q1py from STG where a.sub_bu = 'TSG' and a.rhead = b.rhead)
    When sub_bu as 'R & D' and road in ('Region owned opex', '% of income', "opex Région", "Région opex %") then
    (select q1py from STG where a.sub_bu like 'STG' and a.rhead = b.rhead)
    ANY other purpose like STG q1py_tot b where report_order = 1

    Result:

    Bu road report_order sub_bu_order q1py q1py_bu q1py_tot sub_bu
    order ESS ISS 1162 1 1 1778,4 2953.9

    Here I use the sub query to produce the result. I need to give the same result by using JOINS.

    If someone help me, by using JOINS instead of QUERY SUB and produce the same result



    Thanks in advance

    Maybe you can use SQL as below. (B-)

    select Rhead,bu,Sub_bu,report_order,sub_bu_order,q1py,
    case
    when sub_bu='ISS'
    then max(case when sub_bu='ESS' then q1py end)
    over(partition by rhead)
    when sub_bu='TS'
    then max(case when sub_bu='Services' then q1py end)
    over(partition by rhead)
    when sub_bu='SW'
    then max(case when sub_bu='SW' then q1py end)
    over(partition by rhead)
    end as q1py_bu
    from tsg
     where report_order=1;
    
  • Internal XML to the query with join

    I have a CF page that reads an XML file in a query using < cffile > XMLParse and QueryAddrow.

    I then do a QoQ on the result and voila! I have my page.  I hide the query for 8 hours and the XML file is only reread this cache expires.  It works well.

    My problem now is that the file contains data from three tables of database instead of one, so I need to make an inner join on the tables.  But I can't do a t/t with an inner join.

    Does anyone know a way for me to do this?

    Oh, didn't know that.  How about interweaving of QofQ?  Join Query1 and Query2 requests in a new query, then join for 3 statement?

  • Hierarchical query with join

    Hi all
    I want to reproduce the following query:
    SQL> select to_char(level,'9') Lev,
    first_name||' '||last_name Name, 
    sys_connect_by_path((select first_name||' '||last_name from employees m where e.manager_id=m.employee_id),'/')Path,
    (select department_name from departments d where d.department_id=e.department_id) Department 
    from employees e 
    start with employee_id=100 
    connect by manager_id=prior employee_id order siblings by 4,3,2;
    
    LE NAME           PATH                      DEPARTMENT
    -- -------------------- ------------------------------ ---------------
     1 Steven King          /                      Executive
     2 Lex De Haan          //Steven King                 Executive
     3 Alexander Hunold     //Steven King/Lex De Haan      IT
     4 Bruce Ernst          //Steven King/Lex De Haan/Alex IT
                   ander Hunold
    
    -- QUERY TRUNCATED --
    
     3 Sarah Bell          //Steven King/Shanta Vollman   Shipping
     3 Stephen Stiles     //Steven King/Shanta Vollman   Shipping
     3 Vance Jones          //Steven King/Shanta Vollman   Shipping
    
    107 rows selected.
    with a JOIN query. This query uses the example of the HR diagram and displays the names of the employees with their managers and departments using join instead of correlated query. So far, I got:
    SQL> select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d 
    where e.manager_id=m.employee_id  and e.department_id=d.department_id;
    
    NAME               MANAGER            DEPARTMENT
    -------------------- -------------------- --------------------
    Lex De Haan          Steven King       Executive
    Neena Kochhar          Steven King       Executive
    Eleni Zlotkey          Steven King       Sales
    Gerald Cambrault     Steven King       Sales
    Alberto Errazuriz    Steven King       Sales
    Karen Partners          Steven King       Sales
    
    -- QUERY TRUNCATED --
    
    John Russell          Steven King       Sales
    Kevin Mourgos          Steven King       Shipping
    Shanta Vollman          Steven King       Shipping
    Payam Kaufling          Steven King       Shipping
    Adam Fripp          Steven King       Shipping
    Pat Fay           Michael Hartstein       Marketing
    William Gietz          Shelley Higgins       Accounting
    
    105 rows selected.
    
    SQL> select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d where e.manager_id=m.employee_id  and e.department_id=d.department_id 
    start with e.employee_id=100 connect by e.manager_id=prior e.employee_id;
    
    no rows selected
    
    SQL> 
    But the above query returns lines until I have slides BEGIN WITH CONNECT BY clause, which returns nothing. What is the problem with the START WITH CONNECT BY clause from the second query?

    Best regards
    TA.

    Published by: Valerie good-natured April 18, 2011 02:54

    Employee no. 100 has no manager_id, so you need an outer join:

    select first_name|| ' '||last_name Name,
    Manager,Department from employees e,
    (select first_name||' '||last_name Manager,employee_id,first_name first from employees) m ,
    (select department_name Department,department_id from departments) d where
    e.manager_id=m.employee_id (+)
    and e.department_id=d.department_id (+)
    start with e.employee_id=100 connect by e.manager_id=prior e.employee_id;
    

    Hope this helps,
    Tony

  • creating table using joins in the subquery

    can we create a table using joins in the subquery?
    Like this
    create table emp in select * from employee e, Department d
    where d.department_id = e.department_id
    ??
    We can?

    987018 wrote:
    We can?

    Yes, as long as you column alias names common to both tables to make them unique.

    SY.

  • SPARQL query using varying paths

    Hello

    I have a chart in Oracle I like to do query using Jena 2.6.4 and OracleJenaAdaptor 11.2.0.3

    IND:123: ind:124 hasA
    IND:124: ind:125 Hilmi
    IND:125: hasC ind:126
    IND:123: coward ind:127

    Is there a way to build a sparql query to return all the ind: without 'hard-conding"the full property name? Something in these lines (note that this query doesn't really work).

    Select *.
    where {ind:123 (: has *) +? x}

    Thank you.

    Hello

    If you have created a virtual model before, then will do the following. Note that I am assuming that the virtual model is created based on two 'my_asset', 'my_model' models and modules OWLPRIME.

    Piece attached attachment = Attachment.createInstance (new String() {"my_model"},
    (New String() {"OWLPRIME"}, InferenceMaintenanceMode.UPDATE_WHEN_COMMIT, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP).

    Chart GraphOracleSem = new GraphOracleSem (oracle, "my_asset", room attached, true);
    graph.performInference ();

    Thank you

    Zhe

  • XPath query using DONKEY with AIR3.9 for iOS app

    We build an app for iOS using AIR 3.9 where we load and parse the xml document so that we can read the path of images and download stuff on iOS device. To resolve this issue, we found a solution using XCode via DONKEY where query using XPath such as 'PerformXPathQuery', 'PerformXMLXPathQuery', 'xmlReadMemory"etc.. The code runs and when build Simulator itself on mac computer. But when we're packing DONKEY with AIR 3.9, it gives the error that says that: -.

    Error occurred during the application of packaging:

    For architecture armv7 httpd Undefined symbols:

    "_xmlReadMemory", referenced from:

    _PerformXMLXPathQuery in libnet.example.download.a (ExampleLib.o)

    LD: symbol not found armv7 architecture

    Compilation failed during execution: ld64

    I tried connecting binary with libraries such as 'libxml2.dylib', 'libxml2.2.dylib' and libz.dylib + added header files libXML to the header in the build properties search path, but had no help.

    our AIR 3.9 platform xml looks like: -.

    " < platform xmlns =" http://ns.Adobe.com/air/extension/3.9 ">

    < > 4.0.0 sdkVersion < / sdkVersion >

    < linkerOptions >

    < option > - ios_version_min 4.2 < / option >

    < option > - frame UIKit < / option >

    < option > - framework Foundation < / option >

    < option > - framework CoreText < / option >

    < / linkerOptions >

    < / platform >

    can anyone suggest where we are going wrong!

    Thanks in advance

    Found the solution, it was missing the framework connects to the xPath library in platform.xml

    follow the instuctions from the link below: -.

    http://forums.Adobe.com/thread/1037904

    Thanks to the adobe team

  • Query using progressive relaxation take more time for execution

    HI gurus,

    I'm creating a query using the context and the progressive relaxation index

    I had started using progressive relaxation after obtaining the forum entries {: identifier of the thread = 2333942}. With the help of progressive relaxation takes more than 7 seconds for each request. Is there a way we can improve the query performance?
     create table test_sh4 (text1 clob,text2 clob,text3 clob);
    
    begin
       ctx_ddl.create_preference ('nd_mcd', 'multi_column_datastore');
       ctx_ddl.set_attribute
           ('nd_mcd',
            'columns',
            'replace (text1, '' '', '''') nd1,
             text1 text1,
             replace (text2, '' '', '''') nd2,
             text2 text2');
       ctx_ddl.create_preference ('test_lex1', 'basic_lexer');
       ctx_ddl.set_attribute ('test_lex1', 'whitespace', '/\|-_+');
       ctx_ddl.create_section_group ('test_sg', 'basic_section_group');
       ctx_ddl.add_field_section ('test_sg', 'text1', 'text1', true);
       ctx_ddl.add_field_section ('test_sg', 'nd1', 'nd1', true);
       ctx_ddl.add_field_section ('test_sg', 'text2', 'text2', true);
       ctx_ddl.add_field_section ('test_sg', 'nd2', 'nd2', true);
     end;
    
    create index IX_test_sh4 on test_sh4 (text3)   indextype is ctxsys.context   parameters    ('datastore     nd_mcd   lexer test_lex1 section group     test_sg') ;
    
    alter index IX_test_sh4 REBUILD PARAMETERS ('REPLACE SYNC (ON COMMIT)') ;-- sync index on every commit. 
    
    
    SELECT SCORE(1) score,t.* FROM test_sh4 t WHERE CONTAINS (text3,  '
    <query>
    <textquery>
    <progression>
    <seq>{GIFT GRILL STAPLES CARD} within text1</seq>
    <seq>{GIFTGRILLSTAPLESCARD} within nd1</seq>
    <seq>{GIFT GRILL STAPLES CARD} within text2</seq>
    <seq>{GIFTGRILLSTAPLESCARD} within nd2</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES% and %CARD%)) within text1</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES% and %CARD%)) within text2</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES%) or (%GRILL% and %STAPLES% and %CARD%) or (%GIFT% and %STAPLES% and %CARD%) or (%GIFT% and %GRILL% and %CARD%)) within text1</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES%) or (%GRILL% and %STAPLES% and %CARD%) or (%GIFT% and %STAPLES% and %CARD%) or (%GIFT% and %GRILL% and %CARD%)) within text2</seq>
    <seq>((%STAPLES% and %CARD%) or (%GIFT% and %GRILL%) or (%GRILL% and %CARD%) or (%GIFT% and %CARD%) or (%GIFT% and %STAPLES%) or (%GRILL% and %STAPLES%)) within text1</seq>
    <seq>((%STAPLES% and %CARD%) or (%GIFT% and %GRILL%) or (%GRILL% and %CARD%) or (%GIFT% and %CARD%) or (%GIFT% and %STAPLES%) or (%GRILL% and %STAPLES%)) within text2</seq>
    <seq>((%GIFT% , %GRILL% , %STAPLES% , %CARD%)) within text1</seq>
    <seq>((%GIFT% , %GRILL% , %STAPLES% , %CARD%)) within text2</seq>
    <seq>((!GIFT and !GRILL and !STAPLES and !CARD)) within text1</seq>
    <seq>((!GIFT and !GRILL and !STAPLES and !CARD)) within text2</seq>
    <seq>((!GIFT and !GRILL and !STAPLES) or (!GRILL and !STAPLES and !CARD) or (!GIFT and !STAPLES and !CARD) or (!GIFT and !GRILL and !CARD)) within text1</seq>
    <seq>((!GIFT and !GRILL and !STAPLES) or (!GRILL and !STAPLES and !CARD) or (!GIFT and !STAPLES and !CARD) or (!GIFT and !GRILL and !CARD)) within text2</seq>
    <seq>((!STAPLES and !CARD) or (!GIFT and !GRILL) or (!GRILL and !CARD) or (!GIFT and !CARD) or (!GIFT and !STAPLES) or (!GRILL and !STAPLES)) within text1</seq>
    <seq>((!STAPLES and !CARD) or (!GIFT and !GRILL) or (!GRILL and !CARD) or (!GIFT and !CARD) or (!GIFT and !STAPLES) or (!GRILL and !STAPLES)) within text2</seq>
    <seq>((!GIFT , !GRILL , !STAPLES , !CARD)) within text1</seq>
    <seq>((!GIFT , !GRILL , !STAPLES , !CARD)) within text2</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES and ?CARD)) within text1</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES and ?CARD)) within text2</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES) or (?GRILL and ?STAPLES and ?CARD) or (?GIFT and ?STAPLES and ?CARD) or (?GIFT and ?GRILL and ?CARD)) within text1</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES) or (?GRILL and ?STAPLES and ?CARD) or (?GIFT and ?STAPLES and ?CARD) or (?GIFT and ?GRILL and ?CARD)) within text2</seq>
    <seq>((?STAPLES and ?CARD) or (?GIFT and ?GRILL) or (?GRILL and ?CARD) or (?GIFT and ?CARD) or (?GIFT and ?STAPLES) or (?GRILL and ?STAPLES)) within text1</seq>
    <seq>((?STAPLES and ?CARD) or (?GIFT and ?GRILL) or (?GRILL and ?CARD) or (?GIFT and ?CARD) or (?GIFT and ?STAPLES) or (?GRILL and ?STAPLES)) within text2</seq>
    <seq>((?GIFT , ?GRILL , ?STAPLES , ?CARD)) within text1</seq>
    <seq>((?GIFT , ?GRILL , ?STAPLES , ?CARD)) within text2</seq>
    </progression>
    </textquery>
    <score datatype="FLOAT" algorithm="default"/>
    </query>',1) >0 ORDER BY score(1) DESC

    Progressive relaxation works best when you select only a limited number of lines. If you retrieve ALL the rows that satisfy the query, then every step of easing should run without worrying.

    If you collect - say - the first 10 results, then if the first step in the relaxation gives 10 results so there is no need to execute the next step (actually, due to the internal buffering, which won't be exactly true but he is theoretically correct).

    The easiest way to proceed is to reformulate the query in the form

    SELECT * FROM)
    (Score select (1) SCORE, t.* FROM test_sh4 t WHERE CONTAINS (Text3, '))


    ...


    (1) > 0 ORDER BY score (1) DESC
    )
    WHERE ROWNUM<=>

    You have discovered that wildcards don't work too well, unless you use SUBSTRING_INDEX. I encourage you to avoid completely if possible, or push down much lower in the progressive relaxation. Usually, GIFT % is a useful term (matches GIFTS, GIFTED, etc.), DON % is generally more effective.

    There are a lot of steps in your progressive relaxation. It you want to reduce the number of steps, you can change:

    ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text1
    ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text2

    TO

    ((CADEAU % et % de la GRILLE et AGRAFES % et CARTE %) * 2) within Text1 ACCUM ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text2

    I don't know if it would have performance benefits - but it is worth trying to see.

  • How can I use join query ANSI in Forms 10 g

    Dear all,

    How I use the query as mentioned below in Forms 10 g

    SELECT <fields>  
      FROM TableA a INNER JOIN TableB b ON a.key = b.key
    

    Kind regards

    Zafar Iqbal

    You cannot use the SQL commands that did not exist in the 8.0 database.

    Oracle Forms (and reports) has a full PL/SQL engine and (only) the SQL parser.

    However, form (and reports) PL/SQL engine / SQL parser is at a level that was in the Oracle 8.0 database.

    Kind regards

    Zlatko

  • Query with join optimization research and details of the extra column

    I have the following SQL used for a report that comes out some stats (with some research of names). There is a good chance it is probably possible to optimize with better SQL, but I also hope to add an additional column, which I'm not sure.

    I want the extra column at one percent, which is total % of the lines of the value of the units, for the combination of category/group.

    Oracle SQL is v11.2.0

    Here's the SQL code, as it is currently:

    select a.date_adjusted, 
           a.task_name,
           sum(case when a.units_adjusted is not null then a.units_adjusted else a.units_original end) Units, 
           b.group_name, 
           b.category_name
    from   actuals_intake a
    left join
    -- lookups to obtain group and category names from their ID's in the groupings table
           (select c.task_id, 
                   d.group_name, 
                   e.category_name, 
                   c.business_unit_id
            from   task_groupings c,
                   task_groups d,
                   task_categories e
            where  c.group_id = d.id
            and    c.business_unit_id = d.business_unit_id
            and    c.category_id = e.id
            and    c.business_unit_id = e.business_unit_id
    ) b
    on    a.task_id = b.task_id
    and   a.business_unit_id = b.business_unit_id
    where a.business_unit_id = :P10_SELECT_BUSINESS_UNIT
    and   a.date_adjusted between to_date(:P10_DATE_START, 'dd-mon-yyyy') and to_date(:P10_DATE_END, 'dd-mon-yyyy')
    group by a.date_adjusted, a.task_name, b.group_name, b.category_name
    order by a.date_adjusted, b.category_name, b.group_name
     

    This will set up the tables and data:

    CREATE TABLE ACTUALS_INTAKE (
    ID NUMBER,
    DATE_ORIGINAL DATE,
    TASK_NAME VARCHAR2(500 CHAR),
    TASK_ID NUMBER,
    UNITS_ORIGINAL NUMBER,
    BUSINESS_UNIT_ID NUMBER,
    SUB_UNIT_ID NUMBER,
    DATE_ADJUSTED DATE,
    UNITS_ADJUSTED NUMBER
    );
    CREATE TABLE TASK_CATEGORIES (
    ID NUMBER, 
    CATEGORY_NAME VARCHAR2(100 CHAR), 
    BUSINESS_UNIT_ID NUMBER
    );
    CREATE TABLE TASK_GROUPS (
    ID NUMBER, 
    GROUP_NAME VARCHAR2(100 CHAR), 
    BUSINESS_UNIT_ID NUMBER
    );
    CREATE TABLE TASK_GROUPINGS (
    TASK_ID NUMBER, 
    GROUP_ID NUMBER, 
    CATEGORY_ID NUMBER, 
    BUSINESS_UNIT_ID NUMBER
    );
     
     
    INSERT ALL
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (1, '03/15/2014', 'Task One', 1, 200, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (2, '03/15/2014', 'Task Two', 2, 30, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (3, '03/15/2014', 'Task Three', 3, 650, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (4, '03/15/2014', 'Task Four', 4, 340, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (5, '03/14/2014', 'Task Four', 4, 60, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (6, '03/15/2014', 'Task Five', 5, 15, 10, null, '03/15/2014', null)
    INTO ACTUALS_INTAKE (ID, DATE_ORIGINAL, TASK_NAME, TASK_ID, UNITS_ORIGINAL, BUSINESS_UNIT_ID, SUB_UNIT_ID, DATE_ADJUSTED, UNITS_ADJUSTED)
    VALUES (7, '03/15/2014', 'Task Six', 6, 40, 10, null, '03/15/2014', null)
    SELECT 1 FROM DUAL;
     
     
    INSERT ALL
    INTO TASK_GROUPS (ID, GROUP_NAME, BUSINESS_UNIT_ID)
    VALUES (1, 'Group One', 10)
    INTO TASK_GROUPS (ID, GROUP_NAME, BUSINESS_UNIT_ID)
    VALUES (2, 'Group Two', 10)
    INTO TASK_GROUPS (ID, GROUP_NAME, BUSINESS_UNIT_ID)
    VALUES (3, 'Group Three', 10)
    select 1 from dual;
    
     
    INSERT ALL
    INTO TASK_CATEGORIES (ID, CATEGORY_NAME, BUSINESS_UNIT_ID)
    VALUES (1, 'Category A', 10)
    INTO TASK_CATEGORIES (ID, CATEGORY_NAME, BUSINESS_UNIT_ID)
    VALUES (2, 'Category A', 10)
    INTO TASK_CATEGORIES (ID, CATEGORY_NAME, BUSINESS_UNIT_ID)
    VALUES (3, 'Category B', 10)
    select 1 from dual;
    
     
    INSERT ALL
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (1, 1, 1, 10)
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (2, 1, 1, 10)
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (3, 2, 2, 10)
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (4, 2, 3, 10)
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (5, 3, 3, 10)
    INTO TASK_GROUPINGS (TASK_ID, GROUP_ID, CATEGORY_ID, BUSINESS_UNIT_ID)
    VALUES (6, 3, 3, 10)
    select 1 from dual;
     

    Results will look like this. The last column is what I want the extra column to look like:

    Date_Adjusted TaskName Units of GroupName Category_Name Units %
    15/03/2014A task200Group 1Category A87
    15/03/2014Task 230Group 1Category A13
    15/03/2014Task 3650Group twoCategory A100
    15/03/2014Task 515Group threeCategory B27
    15/03/2014Task 640Group threeCategory B73
    15/03/2014Task 4400Group twoCategory B100

    Hope all that makes sense... Anyone able to help me do this effectively?

    Hello

    Use the analytical RATIO_TO_REPORT function to calculate the % of units column.

    If you're serious about performance, please refer to the Forum:

    Re: 3. how to improve the performance of my query? / My query is slow.

    Do you really need an outer join?  Inner joins are faster.  With the given sample data, they produce the same results.

    COALESCE may be a little faster than the CASE.

    Try this:

    WITH got_units AS

    (

    SELECT a.date_adjusted,

    a.Task_Name,

    sum of units (COALESCE (a.units_adjusted, a.units_original));

    b.group_name,

    b.category_name

    of actuals_intake one

    the left join - or just JOINED

    -research for the group names and category of their ID in the table of groupings

    (select c.task_id,

    d.group_name,

    e.category_name,

    c.business_unit_id

    of task_groupings c,.

    task_groups d,

    e task_categories

    where d.id = c.group_id

    and c.business_unit_id = d.business_unit_id

    and c.category_id = e.id

    and c.business_unit_id = e.business_unit_id

    ) b

    On a.task_id = b.task_id

    and a.business_unit_id = b.business_unit_id

    -where a.business_unit_id =: P10_SELECT_BUSINESS_UNIT - if necessary

    - and a.date_adjusted between to_date (: P10_DATE_START, 'Mon-dd-yyyy') and to_date (: P10_DATE_END, ' mon-dd-yyyy "")

    Group of a.date_adjusted, a.task_name, b.group_name, b.category_name

    )

    SELECT u.*

    ROUND (100 * RATIO_TO_REPORT (units) OVER (PARTITION BY groupname)

    category_name

    )

    ) AS units_pct

    OF got_units u

    ORDER BY date_adjusted, category_name, GroupName

    ;

    Thanks for the display of the data of the sample; It is very useful.  Don't try to insert strings, for example, March 15, 2014", in DATE columns.  TO_DATE allows to convert strings to DATEs.

  • How to write a query to join and right join

    Hello

    With the help of 10 gr 2:

    I have a scenario where generate us a report by joining a few tables.

    same goes for ex:

    Select col1, col2, col5, col10 col22...

    from tableA, tableB.

    where tableA.col1 = tableB.col1 etc.

    I have a requirement where choose a flag in the front-end server must be a right join.  so, if the flag is N, I need to return the data returned by the join; but, if the flag is there I need to make a right join and returns all the data corresponding to table A and table B, as well as the data in table B.

    (I did mention only two tables, as they are, they main engines, there are very many other tables joined in this request)

    It is possible to write a query, so that the two scenarios can be addressed based on the flag?

    Thanks in advance

    Hello

    user565033 wrote:

    ... When Oracle treats of the WHERE clause that starts from the bottom or the top?  So it's best to put filters that reject the unnecessary lines at the beginning of the place where clause or end?  Is how important it? ...

    No, it does not matter.

    The optimizer evaluates what condition will be faster and/or more selective (that is, will eliminate the most lines) and make the first condition.

    If the optimzer cannot decide on what terms will be faster or more selective, it can arbitrarily don't close at the end of the WHERE clause first, but, even if you already knew for sure, this is exactly the kind of thing that is likely to change from one version to the other, or platform to another.

    The optimizer (in recent versions, at least) is very good.  If the optimizer can not say what conditions should apply first, then, chances are, there is really no significant difference, so it would be not serious of which one was made first.

    If you read something that indicates the order is important, it is very outdated.  Long ago (version 6), there was no cost-based optimizer and the order of the conditions in the WHERE clause was important.  The cost-based optimizer was introduced in Oracle 7 (1992) and has been greatly improved by Oracle 8.1 (1998).  Also later Oracle 10, the older optimizer ("regulated") was available for those who really want to continue to use it.

  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

    We need to rewrite under request without using the join condition and group by clause?

    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;
    When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
     10  UNION
     11  (SELECT b.title, NULL FROM books b
     12  MINUS
     13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    ------- ------------------------------------------------------------
    title 1                                                           14
    title 2                                                           44
    title 3
    

    Lukasz

  • Query using link help?

    I'm quite new in the world of SQL and I'm having a problem with an application using binding. I use SQL Developer (3.1.07).
    If I run the query with no binding, everything works fine. Normal occasions I have run this query on the day I want my totals and I get my desired results:

    HIS SELECTION. CRAFTS, nvl (SUM (SA. (LABORHRS), 0) ' loaded hours. "
    SOL_SCHEDULEBASELINEWOASGMNT SA
    LEFT JOIN SOL_SCHEDULEBASELINE ON SB SB. BASELINEID = SA. BASELINEID
    WHERE SB. DATECODE = "DAILY".
    AND TO_CHAR (SB. FROMDATE, "MON-DD-YYYY") = TO_CHAR (SYSDATE, ' DD-MON-YYYY "")
    AND TO_CHAR (SB. TODATE, 'DD-MON-YYYY') = TO_CHAR (SYSDATE, ' DD-MON-YYYY "")
    AND TO_CHAR (SA. SCHEDULEDATE, "MON-DD-YYYY") = TO_CHAR (SYSDATE, ' DD-MON-YYYY "")
    Sa.craft group
    sa.craft asc order

    BOATS loaded hours
    ---------- -------------------
    CONTROL.     24
    12 MM
    MT 6


    BUT * I want to enter my own date rather than use sysdate. This will be for when I get bored of running this for a day, wonder for the values of an earlier date, etc...
    The value will always be the same for all three date fields (SB. FROMDATE, SB. TO DATE, SA. SCHEDULEDATE)
    I modified the request here and the query still works very well at this stage: (I use April 1, 2012 to my link...)

    HIS SELECTION. CRAFTS, nvl (SUM (SA. (LABORHRS), 0) ' loaded hours. "
    SOL_SCHEDULEBASELINEWOASGMNT SA
    LEFT JOIN SOL_SCHEDULEBASELINE ON SB SB. BASELINEID = SA. BASELINEID
    WHERE SB. DATECODE = "DAILY".
    AND SB. FROMDATE =: DDMONYYYY
    AND SB. TODATE =: DDMONYYYY
    AND TO_CHAR (SA. SCHEDULEDATE, "MON-DD-YYYY") = TO_CHAR (SYSDATE, ' DD-MON-YYYY "")
    Sa.craft group
    sa.craft asc order

    BOATS loaded hours
    ---------- -------------------
    CONTROL.     24
    12 MM
    MT 6

    Now I change my request to what follows, I get a different result:

    HIS SELECTION. CRAFTS, nvl (SUM (SA. (LABORHRS), 0) ' loaded hours. "
    SOL_SCHEDULEBASELINEWOASGMNT SA
    LEFT JOIN SOL_SCHEDULEBASELINE ON SB SB. BASELINEID = SA. BASELINEID
    WHERE SB. DATECODE = "DAILY".
    AND SB. FROMDATE =: DDMONYYYY
    AND SB. TODATE =: DDMONYYYY
    AND SA. SCHEDULEDATE =: DDMONYYYY
    Sa.craft group
    sa.craft asc order

    BOATS loaded hours
    ----------- ------------------
    CONTROL.     10

    All columns have a Date data_type.
    As soon as I change SA. SCHEDULEDATE of

    AND TO_CHAR (SA. SCHEDULEDATE, "MON-DD-YYYY") = TO_CHAR (SYSDATE, ' DD-MON-YYYY "")

    TO

    PAM SCHEDULEDATE =: DDMMYYYY

    He keeps the results I need back.

    Why is this? Does anyone have an idea of what's going on here? Any help would be GREATLY appreciated!
    Thank you

    Hello

    Welcome to the forum!

    I'm not very familiar with SQL Developer. Should bind variables DATE? Other Oracle products; in them, you must use VARCHAR2 variables, like this (which works in SQL * more):

    VARIABLE  ddmonyyyy     VARCHAR2 (11)
    EXEC     :ddmonyyyy := '01-Apr-2012';
    
    SELECT        SA.CRAFT
    ,        NVL (SUM (SA.LABORHRS), 0)     as "Loaded Hours"
    FROM             SOL_SCHEDULEBASELINEWOASGMNT        SA
    LEFT JOIN      SOL_SCHEDULEBASELINE              SB   ON   SB.BASELINEID = SA.BASELINEID
    WHERE     SB.DATECODE                       = 'DAILY'
    AND        TO_CHAR (SB.FROMDATE,     'DD-MON-YYYY') = :ddmonyyyy
    AND        TO_CHAR (SB.TODATE,       'DD-MON-YYYY') = :ddmonyyyy
    AND        TO_CHAR (SA.SCHEDULEDATE, 'DD-MON-YYYY') = :ddmonyyyy
    GROUP BY  sa.craft
    ORDER BY  sa.craft     ASC
    ;
    

    It's very similar to your original query, where you have used TO_CHAR on all your DATE columns.

    Moreover, it would be more effective liaison conve\rt variable of a DATE, rather than convert the DATE on each row of a VARCHAR2. In other words, replace the comparisons as

    AND        TO_CHAR (SA.SCHEDULEDATE, 'DD-MON-YYYY') = :ddmonyyyy
    

    with

    AND        SA.SCHEDULEDATE >= TO_DATE (:ddmonyyyy, 'DD-MON-YYYY')
    AND        SA.SCHEDULEDATE <  TO_DATE (:ddmonyyyy, 'DD-MON-YYYY') + 1
    

    If is a coding more. It is up to you to decide if the efficiency improvement is worth.

    Published by: Frank Kulash, April 1, 2012 20:31

  • Alias a field name in a query to join

    I have a database with spaces in domain names (not my fault).

    I'm having a problem with the query because among the fields on that I join has a space in its name. See the text in bold.

    SELECT *.

    Of employee_passwords

    INNER JOIN employee_general_info

    ON employee_passwords. Employee_id = employees. [Ref used]

    WHERE username = ' #username # ' AND password = ' #password #

    So, I get this error message

    Run database query error.

    [Macromedia] [SQLServer JDBC Driver] [SQL Server] Invalid object name ' employees. ID of the employee.

    Is there a way to alias employees. [Field employee ID]?

    The error is probably from a SELECT *-try the list of all the fields individually, including the [employee ID] field.  You can give it a new name to appear in the results of the query by folding, it:

    SELECT [employee Ref] AS EmployeeID

    but within the query itself, you must use the syntax [employee Ref].

    -reed

  • problem with a query, inner join

    Hello;

    I am trying innerjoin these 2 tables in my request for a page that will allow you to add / modify records. Right now, it tells me that I have a lag of data. I do not see where I was wrong. Can someone help me?


    This is my code:

    < name cfparam = "url. CategoryID"type ="integer"default ="0">
    < name cfparam = 'subID' type = 'integer' default = '#url. CategoryID #">"
    < name cfparam = "subName" default = "" >
    < name cfparam = "CategoryID" default = "" >
    < name cfparam = "Name" default = "" >

    < cfif url. CategoryID GT 0 >
    < name cfquery = "categRec" dataSource = "#APPLICATION.dataSource #" >
    SELECT merchSubCat.subName, merchSubCat.subID, categories. CategoryID, Categories.Name
    OF merchSubCat
    JOIN INTERNAL categories
    ON merchSubCat.CategoryID = categories. CategoryID
    WHERE merchSubCat.subID = < cfqueryparam value = '#url. "CategoryID #" cfsqltype = "cf_sql_integer" >
    < / cfquery >

    <!-if the records were found, store the values->
    < cfif categRec.RecordCount EQ 1 >
    < cfset CategoryID = categRec.subID >
    < cfset subName = categRec.subName >
    < cfset CategoryID = categRec.CategoryID >
    < cfset Name = categRec.Name >
    < / cfif >
    < / cfif >

    It's my mistake:

    Run database query error.

    [Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] Type in an expression mismatch.
    The error occurred in C:\Websites\187914kg3\admin\cms\merchant\merchSub-edit.cfm: line 16

    14 : INNER JOIN Categories
    15 :     ON merchSubCat.CategoryID = Categories.CategoryID
    16 : WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">
    17 : </cfquery>
    18 : 
    

    I don't see what I did wrong, another pair of eyes can see where I missed something?

    Thank you

    I think that you just want to use the URL. CategoryID parameter:


    Ken Ford

Maybe you are looking for