Interesting SQL Question

I have a SQL query problem. I need expert's advice on this.
I have following Table (Retail) in the Database.
Retailer_id Number (36)
HighNo char (10)
LowNo char (10)
HighNo and LowNo columns can have digits and regular characters. Sample Data: 48A, 100, 10021.
My query supposed to get retailer_ids in a certain range of High and Lownos.
For example, between 1000 and 1020 or between 28A and 48B.
Only way to do this is
Select Retailer_id
from Retail
where LowNo <= :mylow
AND HighNo>= :myhigh
AND LENGTH (RTRIM(LowNo) ) = LENGTH (:mylow)
AND LENGTH (RTRIM (HighNo) ) = LENGTH (:myHigh)
Is there any better way?
Thanks in advance
null

I have a SQL query problem. I need expert's advice on this.
I have following Table (Retail) in the Database.
Retailer_id Number (36)
HighNo char (10)
LowNo char (10)
HighNo and LowNo columns can have digits and regular characters. Sample Data: 48A, 100, 10021.
My query supposed to get retailer_ids in a certain range of High and Lownos.
For example, between 1000 and 1020 or between 28A and 48B.
Only way to do this is
Select Retailer_id
from Retail
where LowNo <= :mylow
AND HighNo>= :myhigh
AND LENGTH (RTRIM(LowNo) ) = LENGTH (:mylow)
AND LENGTH (RTRIM (HighNo) ) = LENGTH (:myHigh)
Is there any better way?
Thanks in advance
null

Similar Messages

  • SQL Question Bank and Answers for Practise

    Dear Readers:
    Does any one have any recommendation on SQL question bank and answers where I could practice my SQL.
    I have developed some basic knowledge of SQL thanks to the MS community, but I am looking for some additional Questions or textbook  recommendations which has questions and answers to queries for practice.
    Best Wishes,
    SQL75

    Hi,
    Refer below post.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/446b2247-5124-49c1-90c9-b7fea0aa4f83/sql-dba-books?forum=sqlgetstarted
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • Sql question : TRUNCATE vs Delete

    hi
    this is sql question, i don't know where i should post it, so here it is.
    i just want to know the best usage of each. both commands delete records in a table, one deletes all, and the other can do the same plus option to delete specified records. if i just want to purge the table. which one is better and why? thanks

    this is crucial to my design, i need to be able to
    rollback if one of the process in the transaction
    failed, the whole transaction should rollback. if
    truncate does not give me this capability, then i have
    to consider Delete.From the Oracle manual (sans the pretty formatting):
    TRUNCATE
    Caution: You cannot roll back a TRUNCATE statement.
    Purpose
    Use the TRUNCATE statement to remove all rows from a table or cluster. By default,
    Oracle also deallocates all space used by the removed rows except that specified by
    the MINEXTENTS storage parameter and sets the NEXT storage parameter to the size
    of the last extent removed from the segment by the truncation process.
    Removing rows with the TRUNCATE statement can be more efficient than dropping
    and re-creating a table. Dropping and re-creating a table invalidates the table?s
    dependent objects, requires you to regrant object privileges on the table, and
    requires you to re-create the table?s indexes, integrity constraints, and triggers and
    respecify its storage parameters. Truncating has none of these effects.
    See Also:
    DELETE on page 16-55 and DROP TABLE on page 17-6 for
    information on other ways to drop table data from the database
    DROP CLUSTER on page 16-67 for information on dropping
    cluster tables
    Prerequisites
    To truncate a table or cluster, the table or cluster must be in your schema or you
    must have DROP ANY TABLE system privilege.

  • Urgent SQL question : how to flip vertical row values to horizontal ?

    Hello, Oracle people !
    I have an urgent SQL question : (simple for you)
    using SELECT statement, how to convert vertical row values to horizontal ?
    For example :
    (Given result-set)
    MANAGER COLUMN1 COLUMN2 COLUMN3
    K. Smith ......1
    K. Smith ...............1
    K. Smith ........................1
    (Needed result-set)
    MANAGER COLUMN1 COLUMN2 COLUMN3
    K. Smith ......1 .......1 .......1
    I know you can, just don't remeber how and can't find exactly answer I'm looking for. Probably using some analytic SQL function (CAST OVER, PARTITION BY, etc.)
    Please Help !!!
    Thanx !
    Steve.

    scott@ORA92> column vice_president format a30
    scott@ORA92> SELECT f.VICE_PRESIDENT, A.DAYS_5, B.DAYS_10, C.DAYS_20, D.DAYS_30, E.DAYS_40
      2  FROM   (select t2.*,
      3                row_number () over
      4                  (partition by vice_president
      5                   order by days_5, days_10, days_20, days_30, days_40) rn
      6            from   t2) f,
      7           (SELECT T2.*,
      8                row_number () over (partition by vice_president order by days_5) RN
      9            FROM   T2 WHERE DAYS_5 IS NOT NULL) A,
    10           (SELECT T2.*,
    11                row_number () over (partition by vice_president order by days_10) RN
    12            FROM   T2 WHERE DAYS_10 IS NOT NULL) B,
    13           (SELECT T2.*,
    14                row_number () over (partition by vice_president order by days_20) RN
    15            FROM   T2 WHERE DAYS_20 IS NOT NULL) C,
    16           (SELECT T2.*,
    17                row_number () over (partition by vice_president order by days_30) RN
    18            FROM   T2 WHERE DAYS_30 IS NOT NULL) D,
    19           (SELECT T2.*,
    20                row_number () over (partition by vice_president order by days_40) RN
    21            FROM   T2 WHERE DAYS_40 IS NOT NULL) E
    22  WHERE  f.VICE_PRESIDENT = A.VICE_PRESIDENT (+)
    23  AND    f.VICE_PRESIDENT = B.VICE_PRESIDENT (+)
    24  AND    f.VICE_PRESIDENT = C.VICE_PRESIDENT (+)
    25  AND    f.VICE_PRESIDENT = D.VICE_PRESIDENT (+)
    26  AND    f.VICE_PRESIDENT = E.VICE_PRESIDENT (+)
    27  AND    f.RN = A.RN (+)
    28  AND    f.RN = B.RN (+)
    29  AND    f.RN = C.RN (+)
    30  AND    f.RN = D.RN (+)
    31  AND    f.RN = E.RN (+)
    32  and    (a.days_5 is not null
    33            or b.days_10 is not null
    34            or c.days_20 is not null
    35            or d.days_30 is not null
    36            or e.days_40 is not null)
    37  /
    VICE_PRESIDENT                     DAYS_5    DAYS_10    DAYS_20    DAYS_30    DAYS_40
    Fedele Mark                                                          35473      35209
    Fedele Mark                                                          35479      35258
    Schultz Christine                              35700
    South John                                                                      35253
    Stack Kevin                                    35701      35604      35402      35115
    Stack Kevin                                    35705      35635      35415      35156
    Stack Kevin                                    35706      35642      35472      35295
    Stack Kevin                                    35707      35666      35477
    Stack Kevin                                               35667      35480
    Stack Kevin                                               35686
    Unknown                             35817      35698      35596      35363      35006
    Unknown                                        35702      35597      35365      35149
    Unknown                                        35724      35599      35370      35155
    Unknown                                                   35600      35413      35344
    Unknown                                                   35601      35451      35345
    Unknown                                                   35602      35467
    Unknown                                                   35603      35468
    Unknown                                                   35607      35475
    Unknown                                                   35643      35508
    Unknown                                                   35644
    Unknown                                                   35669
    Unknown                                                   35684
    Walmsley Brian                                 35725      35598
    23 rows selected.

  • An interesting synchronization question

    hey all, I have an interesting synchronization question to ask you.
    Suppose that I have 20 tasks and 8 worker threads, each worker is assigned a task by the main thread, and then main thread suspends until one worker has finished its task. Then main thread create another task and handles to a new worker thread until all tasks are finished.
    so code in main thread is something like this.
    boolean has_more_task, has_more_worker;
    do {
                  if (has_more_task && has_more_worker)
                               *  create new thread and assign it a new task
                  else if ( has_more_task && !has_more_worker)
                            wait();
                   else if ( !has_more_task && has_more_worker)
                              wait();
    } while (has_more_task || has_more_worker)the problem is that I don't quite familiar with synchronized key word. so I don't know how to share a synchronized vaiable between main thread and worker thread. can anybody do me a help?
    Remember that main thread should be waken up by either of the 8 worker threads !!

    you can follow producer consumer conept
    create a queue. main thread will push task in queue.
    and worker threads will consumer task from queue.
    you just need to synchronize operation on queue.
    when there is no task in queue then worker thread will notify to main thread and
    will call wait().
    then main thread again put the more task in queue and send notification signal to worker thread and then call wait().
    Class JobQueue
    //should be called by worker thread
    public synchronized getNextTask()
    //shoule be invoked by main thread
    public synchronized addMoreTask()
    }

  • SQL Question - Interesting One

    I need to write a SINGLE SQL statement which has two different
    queries, if the first query retrieves records then there is no
    need to execute the second one, if the first query doesn't
    retrieve the records then I need to make use of second query to
    retrieve records.
    Is it possible to do in a SINGLE SQL statement? I want to use it
    in building a View, i.e, the reason why I am looking for SINGLE
    SQL statement
    For example,
    First Query :- Select Ename from Emp where Deptno=10 and Sal=100;
    If this query can retrieve records then I need not execute the
    second query
    Second Query :- Select Ename from Emp where Deptno=10;
    Any help much appreciated?
    Thanks,
    Venu

    John,
    My understanding of the requirements is that, if there are rows
    where deptno = 10 and sal = 100, then the query should return
    only those rows that meet that criteria. However, if there are
    no rows where deptno = 10 and sal = 100, then the query should
    return all rows where deptno = 10, regardless of the sal.
    I included some tests and results below. In the first test, I
    used the emp demo table with test data that did not include any
    rows where deptno = 10 and sal = 100. I then demonstrated a
    query that correctly returned 3 rows where deptno = 10. I then
    ran your query which incorrectly resulted in no rows returned.
    Then I added a row where deptno = 10 and sal = 100 and re-ran
    both queries and they both correctly returned only the 1 row
    where deptno = 10 and sal = 100.
    In the next test, I created a table similar to your table and
    inserted the sample data that you provided, which did not
    include any rows where ft_pct = 30. I ran both queries and they
    both correctly returned 14 rows where job_no = 'EG01'. Then, I
    added a row where ft_pct = 30 and re-ran both queries. My query
    correctly returned only the one row where ft_pct = 30. Your
    query incorrectly returned 15 rows, which included the original
    14 and the one I added, instead of just the one I added.
    The manner in which your query performed with your data is what
    I expected it to do. However, I don't understand why it seems
    to behave differently with the emp demo data. With one table it
    produces the wrong results under one condition and with the
    other table it produces the wrong results under the other
    condition.
    Barbara
    SQL> -- test using emp demo table:
    SQL> -- table structure:
    SQL> DESC emp
    Name              Null?    Type
    EMPNO             NOT NULL NUMBER(4)
    ENAME                      VARCHAR2(10)
    JOB                        VARCHAR2(9)
    MGR                        NUMBER(4)
    HIREDATE                   DATE
    SAL                        NUMBER(7,2)
    COMM                       NUMBER(7,2)
    DEPTNO                     NUMBER(2)
    SQL> DELETE FROM emp
      2  WHERE  deptno = 10
      3  AND    sal = 100
      4  /
    1 row deleted.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL> -- test data without sal = 100:
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  /
    ENAME          DEPTNO        SAL       
    SMITH              20        800       
    ALLEN              30       1600       
    WARD               30       1250       
    JONES              20       2975       
    MARTIN             30       1250       
    BLAKE              30       2850       
    CLARK              10       2450       
    SCOTT              20       3000       
    KING               10       5000       
    TURNER             30       1500       
    ADAMS              20       1100       
    JAMES              30        950       
    FORD               20       3000       
    MILLER             10       1300       
    14 rows selected.
    SQL> -- query with correct results:
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  WHERE  deptno = 10
      4  AND    sal = 100
      5  UNION
      6  SELECT ename, deptno, sal
      7  FROM   emp
      8  WHERE  deptno = 10
      9  AND    NOT EXISTS
    10           (SELECT ename, deptno, sal
    11            FROM   emp
    12            WHERE  deptno = 10
    13            AND    sal = 100)
    14  /
    ENAME          DEPTNO        SAL       
    CLARK              10       2450       
    KING               10       5000       
    MILLER             10       1300       
    SQL> -- QUERY WITH WRONG RESULT:
    SQL> -- ???????????????????????
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  WHERE  (deptno=10 and sal=100)
      4  OR     deptno=10
      5  /
    no rows selected
    SQL> -- ???????????????????????
    SQL> -- ABOVE RESULT IS WRONG
    SQL> INSERT INTO emp (empno, ename, deptno, sal)
      2  VALUES (9999, 'TEST', 10, 100)
      3  /
    1 row created.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL> -- test data with sal = 100
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  /
    ENAME          DEPTNO        SAL       
    SMITH              20        800       
    ALLEN              30       1600       
    WARD               30       1250       
    JONES              20       2975       
    MARTIN             30       1250       
    BLAKE              30       2850       
    CLARK              10       2450       
    SCOTT              20       3000       
    KING               10       5000       
    TURNER             30       1500       
    ADAMS              20       1100       
    JAMES              30        950       
    FORD               20       3000       
    MILLER             10       1300       
    TEST               10        100       
    15 rows selected.
    SQL> -- query with correct results:
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  WHERE  deptno = 10
      4  AND    sal = 100
      5  UNION
      6  SELECT ename, deptno, sal
      7  FROM   emp
      8  WHERE  deptno = 10
      9  AND    NOT EXISTS
    10           (SELECT ename, deptno, sal
    11            FROM   emp
    12            WHERE  deptno = 10
    13            AND    sal = 100)
    14  /
    ENAME          DEPTNO        SAL       
    TEST               10        100       
    SQL> -- query with correct results:
    SQL> SELECT ename, deptno, sal
      2  FROM   emp
      3  WHERE  (deptno=10 and sal=100)
      4  OR     deptno=10
      5  /
    ENAME          DEPTNO        SAL       
    TEST               10        100       
    SQL> -- test using org_t table:
    SQL> CREATE TABLE org_t
      2    (org_cd VARCHAR2 (5) NOT NULL,
      3       job_no VARCHAR2 (4) NOT NULL,
      4       ft_pct NUMBER (3) NOT NULL)
      5  /
    Table created.
    SQL> INSERT INTO org_t
      2    VALUES ('03538', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('06763', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08026', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08105', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08200', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08232', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08233', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08286', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08909', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('08984', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('09073', 'EG01', 40)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('09723', 'EG01', 1)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('09724', 'EG01', 100)
      3  /
    1 row created.
    SQL> INSERT INTO org_t
      2    VALUES ('09752', 'EG01', 1)
      3  /
    1 row created.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL> -- test data without ft_pct = 30:
    SQL> SELECT org_cd, job_no, ft_pct
      2  FROM   org_t
      3  /
    ORG_C JOB_     FT_PCT                  
    03538 EG01         40                  
    06763 EG01         40                  
    08026 EG01         40                  
    08105 EG01         40                  
    08200 EG01         40                  
    08232 EG01         40                  
    08233 EG01         40                  
    08286 EG01         40                  
    08909 EG01         40                  
    08984 EG01         40                  
    09073 EG01         40                  
    09723 EG01          1                  
    09724 EG01        100                  
    09752 EG01          1                  
    14 rows selected.
    SQL> -- query with correct results:
    SQL> SELECT org_cd, job_no, ft_pct
      2  FROM   org_t
      3  WHERE  job_no = 'EG01'
      4  AND    ft_pct = 30
      5  UNION
      6  SELECT org_cd, job_no, ft_pct
      7  FROM   org_t
      8  WHERE  job_no = 'EG01'
      9  AND    NOT EXISTS
    10           (SELECT org_cd, job_no, ft_pct
    11            FROM   org_t
    12            WHERE  job_no = 'EG01'
    13            AND    ft_pct = 30)
    14  /
    ORG_C JOB_     FT_PCT                  
    03538 EG01         40                  
    06763 EG01         40                  
    08026 EG01         40                  
    08105 EG01         40                  
    08200 EG01         40                  
    08232 EG01         40                  
    08233 EG01         40                  
    08286 EG01         40                  
    08909 EG01         40                  
    08984 EG01         40                  
    09073 EG01         40                  
    09723 EG01          1                  
    09724 EG01        100                  
    09752 EG01          1                  
    14 rows selected.
    SQL> -- query with correct results:
    SQL> SELECT org_cd,job_no,ft_pct
      2  FROM   org_t
      3  WHERE  (job_no = 'EG01' and ft_pct = 30)
      4  OR     job_no = 'EG01'
      5  /
    ORG_C JOB_     FT_PCT                  
    03538 EG01         40                  
    06763 EG01         40                  
    08026 EG01         40                  
    08105 EG01         40                  
    08200 EG01         40                  
    08232 EG01         40                  
    08233 EG01         40                  
    08286 EG01         40                  
    08909 EG01         40                  
    08984 EG01         40                  
    09073 EG01         40                  
    09723 EG01          1                  
    09724 EG01        100                  
    09752 EG01          1                  
    14 rows selected.
    SQL> INSERT INTO org_t
      2  VALUES ('99999', 'EG01', 30)
      3  /
    1 row created.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL> -- test with ft_pct = 30:
    SQL> -- query with correct results:
    SQL> SELECT org_cd, job_no, ft_pct
      2  FROM   org_t
      3  WHERE  job_no = 'EG01'
      4  AND    ft_pct = 30
      5  UNION
      6  SELECT org_cd, job_no, ft_pct
      7  FROM   org_t
      8  WHERE  job_no = 'EG01'
      9  AND    NOT EXISTS
    10           (SELECT org_cd, job_no, ft_pct
    11            FROM   org_t
    12            WHERE  job_no = 'EG01'
    13            AND    ft_pct = 30)
    14  /
    ORG_C JOB_     FT_PCT                  
    99999 EG01         30                  
    SQL> -- QUERY WITH WRONG RESULT:
    SQL> -- ???????????????????????
    SQL> SELECT org_cd,job_no,ft_pct
      2  FROM   org_t
      3  WHERE  (job_no = 'EG01' and ft_pct = 30)
      4  OR     job_no = 'EG01'
      5  /
    ORG_C JOB_     FT_PCT                  
    03538 EG01         40                  
    06763 EG01         40                  
    08026 EG01         40                  
    08105 EG01         40                  
    08200 EG01         40                  
    08232 EG01         40                  
    08233 EG01         40                  
    08286 EG01         40                  
    08909 EG01         40                  
    08984 EG01         40                  
    09073 EG01         40                  
    09723 EG01          1                  
    09724 EG01        100                  
    09752 EG01          1                  
    99999 EG01         30                  
    15 rows selected.
    SQL> -- ???????????????????????
    SQL> -- ABOVE RESULT IS WRONG

  • General SQL question

    I have seen the following in some sql, but not sure of the difference.
    select abc, NULL from xyz where .....
    select abc, to_char(NULL) from xyz where ....
    my question is there a difference between NULL and TO_CHAR(NULL) ?
    Thanks.

    BluShadow wrote:
    Looks like someone was trying to cast the null to a varchar2 datatype so that SQL knew the datatype of the column. In that case they should have used the CAST function...
    Blu:
    Just out of curiosity, any particular reason for the preference for cast instead of to_datatype(null)? I often use that construct, particularly in union type queries. The cast is sematically meaningless in a union query since the column will get the size of the largest column in the query.
    SQL> set null null
    SQL> select *
      2  from (select 1 id, null c1, to_char(null) c2, cast(null as varchar2(10)) c3 from dual
      3        union all
      4        select 2, 'Hello there', 'Hello there', 'Hello there' from dual);
            ID C1          C2          C3
             1 null        null        null
             2 Hello there Hello there Hello there
    SQL> create view v as
      2  select *
      3  from (select 1 id, null c1, to_char(null) c2, cast(null as varchar2(10)) c3 from dual
      4        union all
      5        select 2, 'Hello there', 'Hello there', 'Hello there' from dual);
    View created.
    SQL> desc v;
    Name               Null?    Type
    ID                          NUMBER
    C1                          VARCHAR2(11)
    C2                          VARCHAR2(11)
    C3                          VARCHAR2(11)About the only place where I would use an explicit cast is if I was "hiding" the content of a column in a view, but needed to maintain the same structure as the table.
    John

  • SQL Questions (New to Cisco)

    Hello. I work for Clarian Health in Indianapolis and am trying to learn as much as possible about the SQL databases, both AWDB and HDS so that I can handle the reporting for our Revenue Cycle Customer Service.
    I am currently working my way through the Database Schema Handbook for Cisco Unified ICM /Contact Center Enterprise & Hosted. I’m also reviewing the explanation pages that are available for the reports on WebView. During my reviews, I have noticed a few things that confuse me.
    My questions are:
    1. Why do a majority of the tables on our SQL Server start with “t_”?
    2. Why do some of the tables have data on the AWDB server but not on the HDS server, and vice versa? (Examples: t_Agent and t_Agent_Team and t_Agent_Team_Member and t_Person are blank on the HDS database but not blank on the AWDB database; but the t_Agent_Logout is blank on the AWDB database and not blank on the HDS database)
    3. When data is moved to the HDS server every 30 minutes, is it also removed from the corresponding AWDB table?
    4. In review of the agent26: Agent Consolidated Daily Report syntax info located on the WebView, 1 of the calculations uses the LoggedOnTimeToHalf from the Agent_Half_Hour table while the remaining calculations uses the same field from the Agent_Skill_Group_Half_Hour table. Can you please tell me why this is? Why would all of the percent calculations not use the data from the same table? (The % of time Agent paused and/or put a task on hold uses the Agent_Half_Hour Table. All other % calculations uses the same field from the Agent_Skill_Group_Half_Hour Table.)
    5. Also in reviewing the agent26: Agent Consolidated Daily Report syntax info, I noticed that it contains the Skill_Group table, the Agent_Half_Hour table and the Media_Routing_Domain table. Both the Skill Group table and the Agen_Half_Hour table contain links to the Media_Routing_Domain table. Which relationship/join is actually utilized for this report?
    6. Why doesn't the LoggedOnTimeToHalf field on both the Agent_Half_Hour table and the Agent_Skill_Group_Half_Hour table have the same value in them?
    7. On the agent_26: Agent Consolidated Daily Report syntax explanation page, the Agent State Times: Log on Duration says that it is derived using the Agent_Half_Hour.LoggedOnTimeToHalf field, but when i convert this field to HH:MM:SS, it does not match the actual WebView report. But, when I use the Agent_Skill_Group_Half_Hour.LoggedOnTimeToHalfHour, it does match. Which one is correct?
    8. On the agent_26: Agent Consolidated Daily Report, why does the Completed Tasks: Transfer Out contain both the TransferredOutCallsToHalf and the NetTransferredOutCallsToHalf fields? What's the difference between the two? What Transfer out data writes to each field?
    Thank you.
    Angie Combest
    Clarian Health
    [email protected]

    You need to be careful when looking at the three databases - Logger, AW, HDS - which use the same schema. But many of what appear to be tables in the AW are really views into the t_ tables in the HDS - the data is not there in the AW DB. You are right to look at the schema - but check with SQL Enterprise to understand a bit more.
    In essence, the AW DB is for configuration data and real-time data. The HDS is for historical data. You can query the AW DB for (say) Call_Type_Half_Hour data and join with the Call_Type table to resolve the call type ID into its name - but the data is really in the HDS through the view.
    The DB design is quite complex and sophisticated - many things are not obvious.
    Keep up your research.
    Regards,
    Geoff

  • SQL question- on how to handle groups of records at a time.

    Hi,
    I have a sql that looks like the following:
    insert into INVALID_DATES_TMP
    (id, gid, created, t_rowid, updated)
    select id, gid, created, rowid, updated
    from TABLE1
    where fix_invalid_date_pkg.is_date_invalid('TABLE1', 'CREATED', ROWID) = 'Y';
    COMMIT;
    What the above sql does is selects all rows from TABLE1 where the CREATED column
    has invalid dates and inserts them into invalid_dates_tmp table. So we can process/fix
    those invalid dates from the temp table. Problem is our DBA said Table1 can have
    millions of rows so the above sql can be very database intensive. So, I need to
    figure out another way that may handle chunks of rows at a time from table1.
    Any ideas are appreciated!
    ThankYou,
    Radhika.

    Hallo,
    in general INSERT AS SELECT is the fastest method to insert into the table.
    Probably you can use direct load ? (Hint APPEND).
    Other options (INSERT IN LOOP or BULK + FORALL) are slower.
    I think, this method is optimal.
    Another question is, the function itself. It is not clear, whether it searches the invalid dates optimal. I suppose strong, that function uses dynamic SQL.
    Why ? It is better to search static . Or you use this function for many other columns ? Could you post the function also ?
    Regards
    Dmytro

  • Parent - child table issue wrt to count - SQL question

    I have a scenario:
    There are 2 tables (parent and child). lets say, case summary table and task level dimension table.
    for every case id in case summary table, there would be multiple tasks in task level dim table with a flag indicator set to 1 for all tasks.
    but while counting the number of cases active with flag indicator 1 (ofcourse when joining case summary table with task dimension table), for a case id only 1 instance of task needs to be accounted (even though it has more than one task , for counting active cases, the flag ind corresponding to a task in a case if set to 1 , then the case is considered active)..but while joining and taking count of case ids with flag indicator as 1, you get the count of every task row of a case which is incorrect logically. how to discard the rest of child records of a case in child table (task dimension table)?
    I am not sure how to achieve this in sql query
    Kindly help!
    Case summary table
    case id, busininess_unit, agent_name
    1001, admin, Ram
    1002, Finance, Sam
    task table
    case id, task_id,task_name, flag_indicator
    1001, 1, 'New', 1
    1001,2, 'Open',1
    1001,3,'In progress',1
    1002, 4, 'New', 1
    (In fact task_id is not a big deal... even you can assume task id doesn't exist..only task name ... )
    now my question... if my query should get the current active cases (ind=1); as per above it should essentially give 2... but my query gives me 4..you know the reason why.. but how do i get the correct count?
    Thanks!

    may be you need just this:
    select count(distinct case_id) from task
    where indicator = 1;
    If this is not what you are looking for, please elaborate and tell us the expected output and rest of the details as mentioned in FAQ Re: 2. How do I ask a question on the forums?:

  • SQL question - please help!

    Hi,
    I am working on a SQL, please help ms with the question
    below .... thanks
    (1)Increase by 10% salary of these captain pilots who have
    traveled more than 800,000 miles.
    Routes | | Flights | |Pilots |
    | | | | |
    #routeID | | #flightNO | |#pilotID |
    depAirportID |        |  airplaneNO| |*name |
    arrAirportID |_______/|  pilotID |\___________|*hours_in_air|
    length       |       \|  routeID |/ |*grade |
    ______________| |_____________| |*salary |
    |____________|

    If the length column in routes is in hours, and it represents
    additional hours to those shown in hours_in_air in pilots, then
    the following should work:
    UPDATE pilots
    SET salary = salary * 1.1
    WHERE pilotid in (SELECT a.pilotid
    FROM pilots a,
         (SELECT b.pilotid,sum(c.length) new_hours
          FROM flights b, routes c
          WHERE b.routeid = c.routeid
          GROUP BY b.pilotid) d
    WHERE a.pilotid = d.pilotid and
          new_hours + hours_in_air >= 80000)I suspect that you probably need to add additional criteria to
    the sub-query from flights and routes to take into account only
    flights since the hours_in_air column from pilots was last
    updated. However, your table structures do not indicate any
    date sensitivity. If the table flights is emptied every time
    hours_in_air is updated, then the query above will work.

  • SQL Question (Select rows with multiple records)

    Hello Gurus,
    I am learning SQL and have a question. Thanks for your time and help.
    I have 2 tables TABLE_AA and TABLE_BB. Both tables have two columns ID, DATA.
    TABLE_AA is connected to TABLE_BB through ID field (TABLE_AA.AA_DATA = TABLE_BB.BB_DATA)
    TABLE_AA
    ~~~~~~~
    AA_ID______AA_DATA
    ~~~~~~~~~~~~~~~~
    1111_______XXXX
    2222_______QQQQ
    3333_______ZZZZZ
    4444_______PPPPP
    ~~~~~~~
    TABLE_BB
    ~~~~~~~
    BB_ID BB_DATA
    ~~~~~~~~~~~~~~~~
    1111_______AAAA
    2222_______BBBB
    3333_______CCCC
    3333_______DDDD
    4444_______EEEE
    I am looking to get those AA_ID values that have multiple in TABLE_BB for their parent reference in TABLE_BB.
    So, from the above example, the sql should return the following as AA_ID 3333 has more than 1 reference value in BB_ID
    AA_ID_____BB_ID
    ~~~~~~~~~~
    3333______CCCC
    3333______DDDD

    Hi,
    It's working fine. !!
    14:10:05 topgun>With a As
    14:10:06   2   (
    14:10:06   3   Select 1111 c1, 'AAAA' c2 From dual Union All
    14:10:06   4    Select 2222 ,   'BBBB'    From dual Union All
    14:10:06   5    Select 3333 ,   'CCCC'    From dual Union All
    14:10:06   6    Select 4444 ,   'DDDD'    From dual
    14:10:06   7   ), b As
    14:10:06   8    (
    14:10:06   9    Select 1111 c1,'AAAA' c2 From dual Union All
    14:10:06  10   Select 2222 ,  'BBBB'    From dual Union All
    14:10:06  11   Select 3333 ,  'CCCC'    From dual Union All
    14:10:06  12   Select 3333 ,  'DDDD'    From dual Union All
    14:10:06  13   Select 4444 ,  'EEEE'    From dual
    14:10:06  14    )
    14:10:06  15   Select c1,
    14:10:06  16           c2
    14:10:06  17     From
    14:10:06  18       (
    14:10:06  19       Select a.c1,
    14:10:06  20              b.c2,
    14:10:06  21             Count(*) over (Partition By a.c1 Order By a.c1) cnt
    14:10:06  22      From  a,
    14:10:06  23             b
    14:10:06  24       Where a.c1 = b.c1
    14:10:06  25        )
    14:10:06  26   Where cnt = 2;
            C1 C2
          3333 CCCC
          3333 DDDD- Pavan Kumar N

  • SQL question for to get a top customer

    Hi All,
    I am prasanna. I have a question on SQL,to get a top customer based on year and customer name.I written query like this. But i got an error.
    select calendar_year,cust_first_name,max(sum(amount_sold)) from sales,times,customers where sales.cust_id=customers.cust_id and times.time_id=sales.time_id group  by calendar_year,cust_first_name
    The error is like this:
    *Error starting at line 1 in command:
    select calendar_year,cust_first_name,max(sum(amount_sold)) from sales,times,customers where sales.cust_id=customers.cust_id and times.time_id=sales.time_id group by calendar_year,cust_first_name
    Error at Command Line:1 Column:7
    Error report:
    SQL Error: ORA-00937: not a single-group group function
    00937. 00000 - "not a single-group group function"*
    *Cause:   
    Action:
    Thanks inadvace
    Regards,
    prasanna

    It is not clear what you want. Code below will return a customer with highest total amout sold regardless of year:
    select  calendar_year,
            cust_first_name,
            total_amount_sold max_amount_sold
      from  (
             select  calendar_year,
                     cust_first_name,
                     sum(amount_sold) total_amount_sold,
                     row_number() over(order by sum(amount_sold) desc) rn
               from  sales,
                     times,
                     customers
               where sales.cust_id=customers.cust_id
                 and times.time_id=sales.time_id
               group by calendar_year,
                     cust_first_name
      where rn = 1
    /Keep in mind, if more than one customer has that highest total amount sold and you want all such customers:
    select  calendar_year,
            cust_first_name,
            total_amount_sold max_amount_sold
      from  (
             select  calendar_year,
                     cust_first_name,
                     sum(amount_sold) total_amount_sold,
                     rank() over(order by sum(amount_sold) desc) rn
               from  sales,
                     times,
                     customers
               where sales.cust_id=customers.cust_id
                 and times.time_id=sales.time_id
               group by calendar_year,
                     cust_first_name
      where rn = 1
    /And if you want top customer for each calendar year:
    select  calendar_year,
            cust_first_name,
            total_amount_sold max_amount_sold
      from  (
             select  calendar_year,
                     cust_first_name,
                     sum(amount_sold) total_amount_sold,
                     row_number() over(partition by calendar_year order by sum(amount_sold) desc) rn
               from  sales,
                     times,
                     customers
               where sales.cust_id=customers.cust_id
                 and times.time_id=sales.time_id
               group by calendar_year,
                     cust_first_name
      where rn = 1
    /Keep in mind, if more than one have that highest total amount sold and you want all such customers:
    select  calendar_year,
            cust_first_name,
            total_amount_sold max_amount_sold
      from  (
             select  calendar_year,
                     cust_first_name,
                     sum(amount_sold) total_amount_sold,
                     rank() over(partition by calendar_year order by sum(amount_sold) desc) rn
               from  sales,
                     times,
                     customers
               where sales.cust_id=customers.cust_id
                 and times.time_id=sales.time_id
               group by calendar_year,
                     cust_first_name
      where rn = 1
    /SY.
    Edited by: Solomon Yakobson on Dec 22, 2011 9:24 AM

  • Abap SQL question

    Hi,
    I need to select the set of records only in Table A, but not in Table B. I think that the correct SQL is:
    select k~vbeln
    into data
    from vbak as k
    inner join vbfa as f on kvbeln = fvbelv
    where f~vbelv is null.
    But the following message appears: u201CNo fields from the right-hand table of a LEFT OUTER JOIN may appear in the WHERE condition: u201CF~VBELBu201Du201D.
    Thanks in advance,
    Ricard.

    Hi Oscar & William,
    first of all: The database meaning of NULL is that for the field in question no value is stored for an existing record.
    In SAP tables we rarely have any NULL values. Only if you extend an existing table, i.e. append a new field, the database will expand the structure but not store INITIAL values for the new field in all records.
    Second, just a hint: although the SAP example uses the mystifying ALIAS (AS) addition for joins, it does not help except reducing the code transparency:
    SELECT vbak~vbeln
           INTO lw_data
           FROM vbak
           INNER JOIN vbfa ON vbak~vbeln = vbfa~vbelv
           WHERE vbfa~vbelv IS NULL.
        <you can do your process here>
    ENDSELECT.
    Is 100 % the same. Nevertheless it will never retrieve a single record because vbelv is never stored as a NULL value.
    I think this can be solved using a subquery
    DATA : lt_data TYPE table of vbak-vbeln.
    SELECT vbeln
           INTO  lt_data  
           FROM vbak
           WHERE NOT EXISTS
              ( SELECT * FROM vbfa WHERE vbelv = vbak~vbeln ).
        <you can do your process here>
    ENDSELECT.
    To be honest: I did not try the code, never played with subqueries though I should do so.
    Regards,
    Clemens

  • Locator SQL Questions

    Gentlemen,
    I have a table in Locator that is made of of polygons (loaded via MapInfo EasyLoader). What I need to do is to send Oracle a latitude and longitude and have Oracle return the polygon in which that location falls in. I am new to loator and so this is probably an easy question. I have been experimenting with SQL statements and I tried the following:
    Select MUSYM From ENCLASS_USER.SOILMU_A_IA001
    Where SDO_INSIDE(sdo_geometry(2001, 8307, sdo_point_type(-94.53825,41.38343, NULL),null,null),GEOLOC) = 'TRUE'
    The error returned indicates the "interface not supportrd without a spatial index". The table has a spatial index, however I think that the problem is with the latitude and longitude portion of the SQL. In the above statement, MUSYM is the value of the column in the polygon table I need returned and GEOLOC is the SDO_GEOMETRY Column. The Lat/Long coordinates are -94.53825,41.38343 in the example above.
    How do I construct this SQL so that it will work?
    Thansk for your help,
    Tim Fast
    Pioneer Hi-Bred International, Inc.

    The SQL that I am using is:
    Select MUSYM From ENCLASS_USER.SOILMU_A_IA001
    Where SDO_INSIDE
    (GEOLOC,sdo_geometry(2001, 8307, sdo_point_type(-94.542208,41.383796, NULL),null,null)) = 'TRUE'
    It should return the MUSYM of "370B"
    I don't know how to send you the sample rows but here are three rows in which the first one is the polygon that should be returned. The columns are "|" delimited when exported form Oracle.
    AREASYMBOL|SPATIALVER|MUSYM|MUKEY|MI_STYLE|MI_PRINX|GEOLOC
    IA001|0|370B|402176||1|(2003, 8307, (-94.54199904, 41.38330203, ), (1, 1003, 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ), (-94.54315104, 41.38333398, -94.54303116, 41.38323597, -94.543029, 41.38314201, -94.54290912, 41.383044, -94.54279212, 41.38304598, -94.54267188, 41.38294797, -94.54232088, 41.38294896, -94.54184208, 41.38256304, -94.541724, 41.38256502, -94.54160484, 41.38246701, -94.54148784, 41.38246899, -94.54136796, 41.38237197, -94.54125096, 41.38237296, -94.54077612, 41.38198803, -94.54077504, 41.38188903, -94.54030596, 41.38150302, -94.54018896, 41.381505, -94.53960684, 41.38102098, -94.53948984, 41.38102296, -94.53902904, 41.38063704, -94.53856212, 41.38063902, -94.53844404, 41.38073496, -94.53844116, 41.380929, -94.53878784, 41.381217, -94.53890412, 41.38121601, -94.53902004, 41.38131303, -94.53913704, 41.381316, -94.53936996, 41.38150698, -94.53937104, 41.38179498, -94.53960396, 41.38179597, -94.53995784, 41.38208397, -94.53996108, 41.38227801, -94.54067892, 41.38285401, -94.54056516, 41.38295004, -94.54056804, 41.38304904, -94.54092804, 41.38333704, -94.54104504, 41.38333497, -94.54128588, 41.38353, -94.54140216, 41.38352901, -94.54164192, 41.383719, -94.54164912, 41.38391196, -94.54153608, 41.38400898, -94.54130316, 41.384007, -94.541076, 41.38420401, -94.54119588, 41.38429698, -94.54119912, 41.38439598, -94.541319, 41.38448904, -94.54132188, 41.38458804, -94.54144104, 41.38468101, -94.54144392, 41.38478001))
    IA001|0|370C2|402178||2|(2003, 8307, (-94.53918312, 41.38067601, ), (1, 1003, 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ), (-94.53523392, 41.378121, -94.535001, 41.37812397, -94.53488616, 41.37802704, -94.53465288, 41.37803001, -94.53453696, 41.377932, -94.53407112, 41.37793398, -94.53395304, 41.37803001, -94.53395304, 41.37812496, -94.53418416, 41.37831999, -94.53417984, 41.37861204, -94.53429504, 41.37870996, -94.53429396, 41.378805, -94.53440916, 41.37890202, -94.53440304, 41.37928902, -94.53428496, 41.37939, -94.53382092, 41.37939198, -94.53370716, 41.37929397, -94.53335904, 41.37929397, -94.53324204, 41.37939099, -94.53324096, 41.37948999, -94.53358404, 41.37977799, -94.53427884, 41.37977799, -94.53439584, 41.37968097, -94.53451212, 41.37967998, -94.53474792, 41.37948297, -94.53521196, 41.37948099, -94.53532608, 41.379579, -94.535208, 41.37967503, -94.53520404, 41.37987303, -94.53531888, 41.379966, -94.53543408, 41.37996897, -94.53566988, 41.37977304, -94.53601908, 41.37977196, -94.53613284, 41.37986997, -94.53625092, 41.37976899, -94.53636684, 41.37977196, -94.53659616, 41.37996303, -94.536594, 41.38006203, -94.53670812, 41.38016004, -94.53670092, 41.38054704, -94.53658284, 41.38064298, -94.53634992, 41.38064199, -94.53623292, 41.38074198, -94.53600108, 41.38074099, -94.535766, 41.38093296, -94.53588084, 41.38103097, -94.53669408, 41.38102899, -94.53692808, 41.38083702, -94.53727692, 41.38083603, -94.53739212, 41.380929))
    IA001|0|570C2|402192||3|(2003, 8307, (-94.54121496, 41.38369497, ), (1, 1003, 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ), (-94.53887784, 41.38449498, -94.53875688, 41.38439697, -94.53863988, 41.38439904, -94.53852108, 41.38430103, -94.53817188, 41.38430103, -94.53805992, 41.38439697, -94.53794292, 41.38439904, -94.53770208, 41.38420896, -94.53746988, 41.38420698, -94.53735, 41.38411401, -94.537233, 41.38411104, -94.53711312, 41.38401798, -94.53653208, 41.38401699, -94.53629088, 41.383827, -94.53582612, 41.38382799, -94.53571488, 41.38392402, -94.53571884, 41.38401897, -94.53584016, 41.38411599, -94.53584304, 41.38421103, -94.53620484, 41.38449903, -94.537134, 41.38449498, -94.53725388, 41.38459299, -94.53725892, 41.38468704, -94.53737916, 41.38478496, -94.53738312, 41.38487901, -94.537503, 41.38497702, -94.53819996, 41.38497702, -94.53831984, 41.385069, -94.53843612, 41.38506801, -94.53855492, 41.38516503, -94.53867084, 41.38516404, -94.53891096, 41.38535898, -94.53902688, 41.385357, -94.539384, 41.385645, -94.53949992, 41.38564401, -94.53961188, 41.38554798, -94.53972816, 41.385546, -94.53995388, 41.38535403, -94.54007016, 41.385357, -94.54018284, 41.38526097, -94.54099392, 41.38525899, -94.54111308, 41.38535196, -94.54122612, 41.38525602, -94.54134204, 41.38525899, -94.54156884, 41.38506603, -94.54156308, 41.38487298, -94.54144392, 41.38478001, -94.54144104, 41.38468101, -94.54132188, 41.38458804, -94.541319, 41.38448904))
    Tim Fast

Maybe you are looking for