selection of values to query where clause

Hi guys, it of maybe a silly question but do not know if I approach the solution in the correct engineering.

At the top of my form, I framed that the user fills out the different values. These values are then used to refine the query results in the block below. I know that I can go in the datablock being interrogated and set the where the clause equal to the value of the text boxes above, but I don't feel it is the right place to do it.

If I do like this when the above text box is empty, it returns no results when infact I want to ask all if the values are left white. So should I put it in motion pre? If so how should we do?

Any help would be greatly appreciated.

Thank you.

In the trigger of the QUERY before block you, just put the value in the corresponding element

  :block.name := :ctrl.selection ;

François

Tags: Oracle Development

Similar Questions

  • Passing the value of the where clause with the page

    Dear friends,

    I have a requirement like when I select a selection list value I should pass this value to sql query where clause without submitting the page

    ex I have a select like: P1_Dept guess I selects the value 10 in this

    then I have a query select * from emp where deptno =: P1_Dept.

    DB. ORACLE 11G

    APEX 4.1.1.00.23

    is this possible? can someone help me please in this topic

    Thanks and greetings

    Vballeda

    Suppose we have the selection list with the name P1_DEPT and query for report

    select * from emp where deptno = :P1_DEPT
    

    We create dynamic Action on the evolution of the P1_DEPT point. We will need two real actions:

    1-> set value action

    Set the Type - > body of the PL/SQL function

    The function of body - > return 1;

    Page item to submit-> P1_DEPT

    Change to delete-> Yes event

    Selecttion Type-> trigger element

    2. action-> Refresh

    Selecttion Type-> region

    Region-> your region of report

  • by the way check box values in the WHERE clause

    Hello

    I created a data block - 'CONTACT' (block of data in database)

    and has an element of database - 'Code', 'Descr '.

    The number of records displayed has the value 5.

    When enabled - value 'Y '.

    Value when disabled - n

    Box mapping of other values - "unchecked."


    I write the code inside "WHEN the BUTTON PRESS. My main goal is to return the number of records from

    According to several conditions and one among them is the CODE which can be single or multiple based on the checked checkbox.

    The requirement is when I check one or more boxes, I should pass the "Code" element values in the WHERE clause.

    I tried to use the simple loop but things havmt worked as shown below.

    The next_record refers to the COCHEE BOX as well, and thus return all the eventhough lines if it is not checked.

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

    -LOOP

    IF: contact.cb = 'Y' THEN

    LOOP

    IF p_where is null then

    p_where: =: contact.code;

    on the other

    p_where: = p_where | «, » || : contact.code;

    end if;

    When the output: system.last_record = "TRUE";

    next_record;

    END LOOP;

    end if;

    -END LOOP;

    MESSAGE ("p_where :'|| p_where);

    MESSAGE (' ');

    END;


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

    And even if I write the LOOP before the first CASE, it returns me the current value and move to the last record.

    Please suggest

    Try something like this:

    FIRST_RECORD;
    
    LOOP
    
      IF :contact.cb = 'Y' THEN
        IF p_where is null then
           p_where := :contact.code;
         else
           p_where := p_where ||','||:contact.code;
         end if;
       END IF;
      exit when :system.last_record = 'TRUE';
      next_record;
    END LOOP;
    
    -- END LOOP;
    MESSAGE ( 'p_where :'||p_where);
    MESSAGE (' ');
    
    END;
    
  • Please Help: query the value of the WHERE clause string

    Hello world
    I try the customers request that has corresponding name, but I get the result of every customer that has the name and surname. Here is my query:
    SELECT * FROM  CUSTOMERS WHERE
     CUSTOMER_FNAME IN
     (
     'JOHN', 'MIKE'
     )
    AND CUSTOMER_LNAME IN
     (
     'DOE', 'MILLER'
     ); 
    I am trying to query customer name JOHN DOE and MIKE MILLER, but I get the results of all names with the names of first/last is not exact match. Is there a way I can get the exact match?


    Thank you
    SM

    Something like

    SQL> -- generating sample data:
    SQL> with customers as (
      2  select  'JOHN' fname, 'DOE' lname from dual union
      3  select  'JO' fname, 'HNDOE' lname from dual union
      4  select  'MIKE' fname, 'DOE' lname from dual union
      5  select  'JOHN' fname, 'MILLER' lname from dual union
      6  select  'MIKE' fname, 'MILLER' lname from dual
      7  )
      8  --
      9  -- actual query:
     10  --
     11  select *
     12  from   customers
     13  where  fname||'~'||lname in ('JOHN~DOE', 'MIKE~MILLER');
    
    FNAM LNAME
    ---- ------
    JOHN DOE
    MIKE MILLER
    
    2 rows selected.
    

    but it's just a way, there is more...

    Published by: Hoek on 2 April 2013 18:20 example change changed, thanks to Frank and APC to report that I really need a break now ;)

  • a slightly different similar query where clause

    Hi all, I am facing a problem with my request.
    I have a query that looks like this

    with names like
    (select name, lastname, id
    FROM table1
    where id = 1
    and type = "enu".
    and asset = 'other '.
    and cashid = 2
    and $vdate = system_date
    )
    Select * from names
    (< joins with other tables)

    the thing is that enu value is past as parameter of the procedure. This is only of value if away from the front end.
    further, I have to spend 2 different values now ("cae", "peq")
    However, for these two values, of what I need not use the active column in where clause and the cashid will have to be change to cashid in (3.4)

    I was thinking a dynamic query construction and function of the value pass, I'll build the query. I am looking for another way to implement these changes with minimal impact on the code. Anyone know how to go around this case?

    with these two new values for the query are very similar with the exception of the active column that is more use and cashid will include an IN clause. only a value will be in the procedure, either enu, cae, peq. for enu, the query must be as above, but for the other two active column values are not in the query and cashid must be cashid in (3.4). How to take care of these scenarios
    with names as
    (select name, lastname, id
       from table1
      where id = 1
        and (
        (type = 'enu' and asset = 'others' and cashid =2)
        or
        (type in ('cae','peq') and cashid in (3,4))
        )
        and vdate = system_date
    )
    select * from names
    
    

    Max

  • Calculate the sum of values of 2 where Clauses

    Hi, sorry to trouble, I have all the data in a database or anything like that, just to think about some of the work I have to do, trying to get ahead. I was wondering how i would be the sum of the values in a column, but with 2 where clauses. By example, if I wanted to the sum of all the values until 18:00 in 1 column and all the after 18:00 for 1 day how I would write this out.

    I don't know how to write separately, i.e.

    select name, sum(values) as after6
    from table
    where time > '18:00'
    group by name;
    

    select name, sum(values) as upto6
    from table
    where time < '18:00'
    group by name;
    

    How can I combine these columns after6 and upto6 next to each other.

    If someone could please advise.

    Thanks in advance

    Select the name,

    sum (case when time > 18:00 ' then 0 otherwise end of values) as after6,.

    sum (case when time< '18:00'="" then="" values="" else="" 0="" end)="" as="">

    table

    Group by name;

    ----

    Ramin Hashimzade

  • Best place to initialize the View object query where clause or params

    Where is the best place to initialize the View object 'where' clause before the page is initially rendered? Or how should it be done?
    Specifically, I can't set these values in the entity or view objects because I need information from the user or information Session
    the user has entered before you navigate to the page. I want to prepare the View object so that the results of the query appears something reasonable
    the first time before using chooses search.

    Note: The view object must exist and I need to access managed beans to define the query.

    Is there an event hook (java code) that can be called before the page is rendered?
    Also, there are hooks that can be called when the user navigates to another tab or page?

    Published by: Greateful Sep 6, 2012 19:48

    Hello

    Check out this blog: https://blogs.oracle.com/aramamoo/entry/an_epic_question_how_to

    Arun-

  • Query where clause of different table without data

    Hello

    Oracle 11g.

    I have a 'Points' table that stores information point.
    In carts, users can record information on these points.
    Then, the user can some carts he wants to apply to display data in a report.

    Here is a minimal example (I hope I didn't too many mistakes):
    create table points (
         pt_id integer,
         pt_type varchar2(1),
         pt_accl varchar2(15),
         pt_class varchar2(10),
         pt_status varchar2(1),
         constraint pk_pt_id primary key(pt_id),
         constraint ck_pt_type check(pt_type in ('B','P', 'S', 'T')),
         constraint ck_pt_status check(pt_status in ('A','E'))
    );
    
    create table carts(
         cart_id integer,
         cart_name varchar2(30),
         cart_current varchar2(1),
         constraint pk_cart_id primary key(cart_id),
         constraint ck_cart_current check(cart_current in ('Y','N')) 
    );
    
    create table user_selected_types(
         ust_id integer,
         ust_cart_id integer,
         ust_type varchar2(1),
         constraint pk_ust_id primary key(ust_id),
         constraint fk_ust_cart_id foreign key(ust_cart_id) references carts(cart_id)
    );
    
    create table user_selected_accls(
         usa_id integer,
         usa_cart_id integer,
         usa_accl varchar2(15),
         constraint pk_usa_id primary key(usa_id),
         constraint fk_usa_cart_id foreign key(usa_cart_id) references carts(cart_id)
    );
    
    create table user_selected_classes(
         usc_id integer,
         usc_cart_id integer,
         usc_class varchar2(10),
         constraint pk_usc_id primary key(usc_id),
         constraint fk_usc_cart_id foreign key(usc_cart_id) references carts(cart_id)
    );
    
    create table user_selected_status(
         uss_id integer,
         uss_cart_id integer,
         uss_status varchar2(1),
         constraint pk_uss_id primary key(uss_id),
         constraint fk_uss_cart_id foreign key(uss_cart_id) references carts(cart_id)
    );
    
    insert into carts values (1, 'cart_1', 'N');
    insert into carts values (2, 'cart_2', 'Y');
    insert into carts values (3, 'cart_3', 'Y');
    
    insert into points values (1, 'B', 'AAA', 'AAKCM', 'A');
    insert into points values (2, 'B', 'BIONH1', 'AAKCM', 'A');
    insert into points values (3, 'B', 'BIONH1', 'AAKCM', 'E');
    insert into points values (4, 'B', 'CTF1', 'RF45Q33', 'E');
    insert into points values (5, 'T', 'L4C', 'H4V1', 'A');
    insert into points values (6, 'T', 'L4C', 'H4V1', 'E');
    insert into points values (7, 'S', 'BIONH1', 'RX4', 'A');
    insert into points values (8, 'S', 'L4D', 'L2585', 'A');
    insert into points values (9, 'S', 'L4D', 'L2585', 'E');
    insert into points values (10, 'S', 'CTF1', 'CCMBQX', 'A');
    insert into points values (11, 'S', 'CTF1', 'CCMBQX', 'E');
    insert into points values (12, 'S', 'CTF2', 'CCMBQX', 'A');
    insert into points values (13, 'S', 'CTF2', 'CCMBQX', 'E');
    insert into points values (14, 'P', 'H4', 'L44W', 'A');
    insert into points values (15, 'P', 'H4', 'L44W', 'E');
    insert into points values (16, 'P', null, 'RK', 'E');
    
    insert into user_selected_types values (1, 1, 'B');
    insert into user_selected_types values (2, 1, 'S');
    insert into user_selected_types values (3, 3, 'T'); 
    
    insert into user_selected_accls values (1, 1, 'BIONH1');
    insert into user_selected_accls values (2, 2, 'CTF1');
    insert into user_selected_accls values (3, 2, 'CTF2');
    insert into user_selected_accls values (4, 3, 'L4C');
    
    insert into user_selected_classes values (1, 1, 'AAKCM');
    
    insert into user_selected_status values (1, 3, 'A');
    If a user may for example have the following carts (according to the example above):
    cart_1
    Types : 'B', 'S'
    Accls : 'BIONH1'
    Classes : 'AAKCM'
    Status : [All]
    
    cart_2
    Types : [All]
    Accls : 'CTF1', 'CTF2'
    Classes : [All]
    Status : [All]
    
    cart_3
    Types : 'T'
    Accls : 'L4C'
    Classes : [All]
    Status : 'A'
    When no value is selected for an item, it must return all values.

    For now, I have the following query:
    with t as (select cart_id d from carts where cart_current = 'Y')
    select
         *
    from
         points
    where
         ...
         and (
              pt_type in (select ust_type from user_selected_types where ust_cart_id in (select d from T))
              or not exists (select 1 from user_selected_types where ust_cart_id in (select d from T)))
         and (
              nvl(pt_accl, '' - (null)'') in (select nvl(usa_accl, '' - (null)'') from user_selected_accls where usa_cart_id in (select d from T))
              or not exists (select 1 from user_selected_accls where usa_cart_id in (select d from T)))
         and (
              pt_class in (select usc_class from user_selected_classes where usc_cart_id in (select d from t))
              or not exists (select 1 from user_selected_classes where usc_cart_id in (select d from T)))
         and (
              pt_status in (select uss_status from user_selected_status where uss_cart_id in (select d from T))
              or not exists (select 1 from user_selected_status where uss_cart_id in (select d from T)))
    It works, but the data or mixed...
    If the user apply cart_2 and cart_3, I don't want to for example points to accl "L4C" with status "E", forthcoming.
    I just want to return the union all selected each carts.

    Of course I can loop over Cart ID, PL_SQL, and build the query dynamically, as:
    for cur_c in (select cart_id d from carts where cart_current = 'Y') loop
         l_query := l_query || 'select ... from ... where ...' || ' union all ';
    end loop;
    l_query := substr(l_query,1,length(l_query)-11);
    But imagine the user ask 500 wagons..., I've reached the limit of varchar2.
    I can't use a CLOB that I use Oracle APEX to view the report, and he expects the query a varchar2.

    I don't want to use a temporary table, as it is too slow for the application (I've tested).

    You have a solution?

    Thank you.

    Yann.

    Thanks for create/insert statements - makes it much easier to help :D

    Here's one way:

    SQL> select
      2  c.cart_id,
      3  p.pt_id,
      4  p.pt_type,
      5  p.pt_accl,
      6  p.pt_class,
      7  p.pt_status
      8  from carts c
      9  cross join points p
     10  where c.cart_current = 'Y'
     11  and ( not exists(select null from user_selected_types ust where ust.ust_cart_id = c.cart_id)
     12     or p.pt_type in (select ust.ust_type from user_selected_types ust where ust.ust_cart_id = c.cart_id)
     13      )
     14  and ( not exists(select null from user_selected_accls usa where usa.usa_cart_id = c.cart_id)
     15     or p.pt_accl in (select usa.usa_accl from user_selected_accls usa where usa.usa_cart_id = c.cart_id)
     16      )
     17  and ( not exists(select null from user_selected_classes usc where usc.usc_cart_id = c.cart_id)
     18     or p.pt_class in (select usc.usc_class from user_selected_classes usc where usc.usc_cart_id = c.cart_id)
     19      )
     20  and ( not exists(select null from user_selected_status uss where uss.uss_cart_id = c.cart_id)
     21     or p.pt_status in (select uss.uss_status from user_selected_status uss where uss.uss_cart_id = c.cart_id)
     22      )
     23  order by
     24  c.cart_id,
     25  p.pt_id
     26  ;
    
       CART_ID      PT_ID P PT_ACCL         PT_CLASS   P
    ---------- ---------- - --------------- ---------- -
             2          4 B CTF1            RF45Q33    E
             2         10 S CTF1            CCMBQX     A
             2         11 S CTF1            CCMBQX     E
             2         12 S CTF2            CCMBQX     A
             2         13 S CTF2            CCMBQX     E
             3          5 T L4C             H4V1       A
    
    6 rows selected.
    

    The cross join creates all the possible combinations of carriage/point. Then they are checked for 4 columns according to your rules. I think that the result is correct, if I read your question right?

    If it's the most effective depends a lot on your actual data. Are the usual cases each cart sets a very small subset of points, or each cart will usually define a substantial part of the points. Carts of how are your tables? How many tables of user_selected_? How is the distribution? How many points? Indexes are available?

    If the data are such that it can "pay" to build all of the possible production and "weed" down, then the foregoing can be very effective. If the data is such that the result is usually very small subset then the effectiveness may depend on the index are available.

    Test and see if it works for you ;-)
    If it takes hours, so if please give some information on the quantity and distribution of the data and the expected quantity and size carts etc. Then we could think in a different way...

  • How to pass a value LOV to where clause of another LOV

    Hello

    I have the two LOV project and activity. When I select a value of project LOV this value project to switch to the 2nd activity LOV where clause. How can I achieve this.

    I tried to use the code in the process CO request by getting the value of project with the command below.

    int v_project = Integer.parseInt ((String) passiveCriteria.get ('Project')); grab the critirea project

    and set this value in the setwhereclauseparams of the VO LOV. But the above command is throwing an exception with the exception of null pointer.

    This approach is correct, or should I use any other method.

    Thank you
    HC

    Below you will find the article interesting

    http://oracleanil.blogspot.com/2010/12/dependent-lov-in-OAF.html

    Thank you
    AJ

  • How can I get a non-existent value based on where clause

    For example look at the table

    SQL > select * from emp_temp;

    EMP_NAME AGE
    ---------------------------------------- ----------
    Jay 24
    MUT 25
    Leo 26
    ARA 19



    Select the age of emp_temp years where in (24,25,26,19,30);


    The result I need is 30, since it is the age which is not available in the table.

    In other words I need a query that compares the where values would adopt with the records in the table and give the value not existing.

    (B-) B-) B-)

    select * from table(sys.ODCINumberList(24,25,26,19,30))
    minus
    select age from emp_temp
    
  • Optimize query with function in where clause

    Hello

    I have a query like this:

    SELECT * FROM table_1 t
    WHERE
    (
    -- Clause A (very long clause that filters a lot of rows)
    )
    AND f(t.field) = 'Y' -- This function is heavy but it should filter few rows
    

    This query, it is very slow because I think he's trying to evaluate f() for all rows in table_1.

    Howerver, if I have database query:

    SELECT f(t.field) FROM table_1 t
    WHERE
    (
    -- very long clause that filters a lot of rows
    )
    

    It's very fast.

    How can I reference the query to filter the lines of division A, then by function?

    Thanks in advance!

    If you wrap the function in a select clause then the optimizer can use a scalar subquery caching:

    SELECT * FROM table_1 t 

    WHERE  (  -- Clause A (very long clause that filters a lot of rows)  ) 

    AND (Select f(t.field) From Dual) = 'Y' -- This function is heavy but it should filter few rows

  • Where-Clause-Question by using "defined values.

    Hello

    I use 10 gr 2

    It is possible to filter the lines using sets of values in the where clause?

    As for example:
    SELECT a, b, c
      FROM mytable
      WHERE (b,c) IN
        (
          (3,4),
          (6,7),
          (9,1),
          (0,2)
        )
    .. must retrieve only the rows from myTable with sets (pairs) over the top of the list

    It is not difficult to test:

    with my_tab as (select 1 a, 2 b, 3 c from dual union all
                    select 2 a, 2 b, 2 c from dual)
    select * from my_tab
    where (b, c) in ((1,2), (2,3));
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    
  • Question about the order of evaluation of the clause WHERE CLAUSE when the Oracle OF the syntax used to join tables

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?

    Thanks in advance,

    Hello

    dariyoosh wrote:

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...

    The reverse is actually closer to the truth, but we can't really make general statements like that.

    SQL is not a language of the proceedings.  Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it.  In other words, SQL is a language that describes the results you get, not the way to get them.

    The optimizer will do everything what he thinks is faster if it does not change the results.  If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.

    Here is a query looks very much like you posted:

    SELECT d.deptno

    e.ename, e.sal

    OF scott.dept d

    LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno

    WHERE e.sal > = 3000

    ORDER BY d.deptno

    ;

    Output:

    DEPTNO ENAME SAL

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

    10 KING 5000

    20 FORD 3000

    20 3000 SCOTT

    The scott.dept table contains deptnos 30 and 40; Why are they not in the result set?  The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied.  All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.

  • Complex Inner Join and outer subquery where clause to join internal?

    The DDL for this post was too big and I had to put on my site:
    http://www.harbortownsolutions.com/DDLForDORTable.txt

    My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.


    The dates used for reports are:

    SalesDate = 06/04/2009
    SalesDateForLastYear = 2008-06-05
    SalesDateBeginningOfWeek = 01/06/2009
    SalesDateBginningOFWeekLastYear = 2008-06-02

    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT 
        BUSI_DATE as BusinessDate, 
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores); 
    -======= ONLY Guest count and Sales are needed in comparisons against last year    
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this 
    week matched to Tuesday of last year (except for leap year)
    SELECT 
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear   
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear 
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
           
    
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY 
       --=======  
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY   
    Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?

    Also, how would fit the following of HOEK script:
    See how I put 1 field based on another field value

    He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
    For each of the 116 stores in the store table, there must be 1 and only
    registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
    and sometimes there will be 2 (in a case where a manager of database updates)
    After daily treatment) files. If so, the record with Is_posted = 1
    is the one that should be included in the query. The following text accomplishes this:
    -chr (39) is the single quote
     Select StoreId, 
             DollarVariance 
      from   (select store.storeid, 
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance, 
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn  
                   from  myInven inv 
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      
    Can I put this request on the place where clause of the outer to query I put on a JOIN clause?

    So I guess that's why you used the MAX.

    That is right.
    I used CASES to identify and complete the necessary columns since the first set of results (WITH).
    So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most.

  • Group by, with and without where clause

    Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).
    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from 
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;
     

    totalnewby wrote:
    Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).

    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;
    
    SQL> with tmp as
      2  (
      3  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
      4  select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
      5  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual
      6  )
      7  select status,
      8         country,
      9         count(substatus) cnt01,
     10         sum(decode(substatus, 0, 1, 0)) cntincluding0
     11    from tmp
     12   group by status, country
     13  ;
    
    STATUS   COUNTRY      CNT01 CNTINCLUDING0
    -------- ------- ---------- -------------
    COMPLETE GERMANY          3             2
    

Maybe you are looking for