Several Select statements fill Horizontal

Hello
I wonder how to fill these three instructions select a line, horizontal. The data does not correctly from my code below.
The first statement returns 4 rows
The second statement returns 27 lines
The last third statement returns 31 rows
My problem is that when the code below runs more than 500 rows are returned. What I do wrong to not fill the
results.
Example of how the data should look like, I don't understand the third declaration for space.
CUSTOMER NAME - CUST_FIRST_NAME -CUST_LAST_NAME - CUST_CITY | CUSTOMER NAME - CUST_FIRST_NAME -CUST_LAST_NAME - CUST_CITY 
         1                           JOHN                   DOE                 HOUSTON                1                       CHERYL                   JONES                WACO  
         1                           BOB                     BOBBY                DALLAS                 1                       ANNETTE                JONES                AUSTIN
          --this data should not be repeating since the other select statements             1                       TOM                       BOBBY               JACOB
          --has more rows, these rows should be empty                                             1                       TOMMY                   BANKS               ROB
                                                                                                                       1                       BILLY                      HANK                 TOM  
select distinct x.*, y.*, z.*
from
(select count(*) as "CUSTOMER NAME", 
CUST_FIRST_NAME,
CUST_LAST_NAME,  
CUST_CITY
from DEMO_CUSTOMERS
where CUST_FIRST_NAME  like '%A%'
--and HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
ORDER BY CUST_FIRST_NAME ASC) x,
(select count(*) as "CUSTOMER NAME", 
CUST_FIRST_NAME,
CUST_LAST_NAME,  
CUST_CITY
from DEMO_CUSTOMERS
where CUST_FIRST_NAME  not like '%A%'
--and HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
ORDER BY CUST_FIRST_NAME ASC) y,
(select count(*) as "CUSTOMER NAME", 
CUST_FIRST_NAME,
CUST_LAST_NAME,  
CUST_CITY
from DEMO_CUSTOMERS
--where HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
ORDER BY CUST_FIRST_NAME ASC) z;
I hope someone can help me with this, thanks a lot.

Hello

The best is probably the cross join the demo_customer table will be a table that has 3 lines (so that the demo_customers data can be repeated up to 3 times, that the conditions are met), assign a number line (r_num) for the data replcated and pivot so that data on a line by r_num like that :

WITH     cntr     AS
(
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL     <= 3
)
,     got_criteria     AS
(
     SELECT     d.cust_first_name, d.cust_last_name, d.cust_city
     ,     CASE
               WHEN  c.n     = 1
               AND   cust_first_name         LIKE '%A%'
                     THEN  c.n
               WHEN  c.n     = 2
               AND   cust_first_name     NOT LIKE '%A%'
                     THEN  c.n
               WHEN  c.n = 3
               AND   cust_first_name     >= 'A'
                     THEN  c.n
          END     AS crit_num
     FROM          demo_customers     d
     CROSS JOIN     cntr          c
--     WHERE   hire_date     BETWEEN     TO_DATE (:p10_start_date, 'MM/DD/YYYY')      -- Filter as much as possible here
--                    AND     TO_DATE (:p10_end_date,   'MM/DD/YYYY')
)
,     got_r_num     AS
(
     SELECT     got_criteria.*
     ,     DENSE_RANK () OVER ( PARTITION BY  crit_num
                               ORDER BY          cust_first_name
                         ,                cust_last_name     -- Be sure to include these
                         ,             cust_city
                       )      AS r_num
     FROM    got_criteria
     WHERE     crit_num     IS NOT NULL
)
SELECT       r_num
,       NULLIF (COUNT (CASE WHEN crit_num = 1 THEN 1 END), 0)          AS cnt_1
,       MIN   (CASE WHEN crit_num = 1 THEN cust_first_name END)     AS first_name_1
,       MIN   (CASE WHEN crit_num = 1 THEN cust_last_name  END)     AS last_name_1
,       MIN   (CASE WHEN crit_num = 1 THEN cust_city       END)     AS city_1
,       NULLIF (COUNT (CASE WHEN crit_num = 2 THEN 1 END), 0)          AS cnt_2
,       MIN   (CASE WHEN crit_num = 2 THEN cust_first_name END)     AS first_name_2
,       MIN   (CASE WHEN crit_num = 2 THEN cust_last_name  END)     AS last_name_2
,       MIN   (CASE WHEN crit_num = 2 THEN cust_city       END)     AS city_2
,       NULLIF (COUNT (CASE WHEN crit_num = 3 THEN 1 END), 0)          AS cnt_3
,       MIN   (CASE WHEN crit_num = 3 THEN cust_first_name END)     AS first_name_3
,       MIN   (CASE WHEN crit_num = 3 THEN cust_last_name  END)     AS last_name_3
,       MIN   (CASE WHEN crit_num = 3 THEN cust_city       END)     AS city_3
FROM       got_r_num
GROUP BY  r_num
ORDER BY  r_num
;

The result of your sample data is:

.R_ CNT FIRST    LAST                CNT FIRST    LAST                CNT FIRST    LAST
NUM  _1 _NAME_1  _NAME_1  CITY_1      _2 _NAME_2  _NAME_2  CITY_2      _3 _NAME_3  _NAME_3  CITY_3
--- --- -------- -------- ---------- --- -------- -------- ---------- --- -------- -------- ----------
  1   1 ABBY     DUNN     MOBILE       1 JOHN     EDDY     DALLAS       1 ABBY     DUNN     MOBILE
  2   1 EDWARD   TODD     AUSTIN       1 JOHN     JAMES    HOUSTON      1 EDWARD   TODD     AUSTIN
  3                                    1 JOHNNY   GEORGE   CINCY        1 JOHN     EDDY     DALLAS
  4                                    1 MILLY    BROOKS   DE RIDDER    1 JOHN     JAMES    HOUSTON
  5                                                                     1 JOHNNY   GEORGE   CINCY
  6                                                                     1 MILLY    BROOKS   DE RIDDER

This has only to make a pass through the demo_customers table, so I think it will be faster to do a self-join, where you have to make a separate pass mark for each criterion.
Make sure that the analytical got_rnum.r_num ORDER BY clause contains all the columns that have been in your original GROUP BY, even if you don't really care to their order. The main request will make a GROUP BY r_num, so including the columns in this clause ORDER BY to include in the GROUP BY.

The problem with the full outer join is that you still do not put join conditions after the individual tables. After that the each keyword JOIN there will be a table name or a alias and immediately after that must come the key word WE followed by a coindition to join.
I made a mistake earlier: when full outerer joining several tables, would better meet you each new table in each of the previous tables, because it is unclear which of these tables may be missing due to the outer join. In other words, the join condition for f had better be:

ON           f.r_num = COALESCE (d.r_num, e.r_num)

because d.r_num or e.r_num could be NULL, because the outer join.

Tags: Database

Similar Questions

  • Several SELECT statements with COUNTY with different WHERE clauses.

    OK, so for a bit of background on what this is trying to accomplish...
    I have a small group of people in my team and I will use GROUP BY for their names.
    If each person will be on their own line. Next to their names, I want to be able to have several columns that use the ACCOUNT for the different search criteria (no duplicates)

    Overall, it should have their names, and I would like to add the number of tickets that each person has which meet certain criteria (all in different columns)
    I have applications that can do each of these tasks, but is it possible that I can group together on a single table statements, or use subqueries for these results?

    Do you mean you want something like that?

    SQL > ed
    A written file afiedt.buf

    1 with the team (emp_id, emp_name)
    2 (select 1, 'Fred' from dual union all
    3. Select 2, 'Bob' Union double all the
    4. Select 3, 'Jim' to double
    5            )
    6, tickets (emp_id, ticket_type, ticket_id, ticket_desc)
    7 (select 1, 1, 'BUG', 'First billet Freds' double Union all)
    8. Select 2, 1, 'CHANGE', "Freds second ticket" of all the double union
    9 select 3, 1, 'BUG', ' Freds third ticket "of any double union
    10. Select 4, 2, "CHANGE", "Bobs first ticket" of any double union
    11. Select 5, 3, "CHANGE", "Jims first ticket" of any double union
    12. Select 6, 3, "BUG", "Jims second ticket" of all the double union
    13. Select 7, 1, 'BUG', ' Freds fourth ticket ' from dual
    14            )
    15-
    16 END OF TEST DATA
    17-
    18 select emp_name
    19, count (case when ticket_type = 'BUG' then 1 end to another null) and bugs
    20, count (case when ticket_type = 'CHANGE' then 1 end to another null) as changes
    21 of the team t
    22 a left join external tickets tk (t.emp_id = tk.emp_id)
    23 * emp_name group
    SQL > /.

    EMP_ CHANGES OF BUGS
    ---- ---------- ----------
    Bob           0          1
    Fred 3 1
    Jim           1          1

  • SQL select statements

    Hey everybody,

    First of all, Yes, I searched through the 8.5 database schema guide.  As I went through the scheme, I've developed some ideas on how to collect the data you want.  However, if someone has already developed or found the SQL statements (which I'm sure that someone already has) it would help by reducing to the minimum of the buggs in my data collection program.

    All these statistics must be grouped by CSQ and selected for a certain time interval ( and ).  That is, levels of 1 hour.  I have no problem to get a list of results and then perform v.f. to achieve the desired final result.  Also, if I need to run several select statements for tables of essentially two join, please include two statements.  Finally, I saw the RtCSQsSummary table, but I need to collect data for the past, not at this time.

    1 total calls presented by the CSQ

    2. total number of calls answered by the CSQ

    3 total number of calls abandoned by the CSQ

    4. percentage of calls abandoned by CSQ (if it is not stored in the database, I think: /)

    5. average abandon time in seconds (if it is not stored in the DB, I think: sum () /)

    6. service level - % calls answered in 90 seonds by a set of skills (I have seen metServiceLevel in the ContactQueueDetail table; however, I need to find how to configure this threshold for application)

    7. average speed of response by CSQ

    8 average conversation by CSQ calls

    9. the aggregates connected full-time resources or agents CSQ

    10. resources/agents of CSQ ready time

    I realize that some of them should be easy to find (as I always am search in the guide of db schema), but I was reading how a new record is created for each step of the call so I could easily see how I could get inaccurate information without properly developed select statements.

    Any help will be greatly appreciated.

    Brendan

    Brendan,

    I read your message very well.

    You have the schema of database with tables and description. each table has its associated tables (connected with primary and foreign keys). I think you should start the tables to determine what you need.

    Cisco uses the stored procedure to prepare the reports. the stored procedure is 'sp_csq_interval' to create the report.

    Activity report of Queue Service contact"

    HTH

    Anas

    Please note all useful posts

  • How to format the output of a .sql script that has select statements.

    Hello

    I have a .sql script which is having several select statements. Each Select statement is to have hundreds of Table columns.

    When we run the .sql script, we are unable to read the output.

    Please let know us the commands that we include for better readable output format.

    You work with the lin standard set 80.
    Increase this setting to set lin 3000 or more.

  • Several results of the Select statement horizontally

    Hello

    DB Version: Oracle 11.1.2.1.0

    OS: OEL5

    I try to print the results of several SELECT horizontally using SQL statements, but not able to reach my goal.

    Multiple SQLs:

    SELECT 'DB Version', version db_version FROM v$instance
    UNION ALL
    select 'Oracle Client', length(addr)*4 || '-bits' word_length from v$process where ROWNUM =1
    UNION ALL
    select 'Database Edition', trim(substr(banner,20,19)) from v$version where rownum<2
    UNION ALL
    SELECT 'Single Instance or RAC', CASE COUNT(1) WHEN 1 THEN 'Single Instance' ELSE 'RAC' END is_single_instance FROM gv$instance
    UNION ALL
    SELECT 'No of CPUS', to_char(value) FROM v$osstat WHERE stat_name='NUM_CPUS'
    UNION ALL
    SELECT 'No of CPU Cores', to_char(value) FROM v$osstat  WHERE stat_name='NUM_CPU_CORES'
    UNION ALL
    SELECT 'No of CPU Sockets', to_char(value) FROM v$osstat  WHERE stat_name='NUM_CPU_SOCKETS'
    UNION ALL
    SELECT 'Physical Memory (GB)', to_char(ROUND((value/1024/1024/1024),3)) FROM v$osstat  WHERE stat_name='PHYSICAL_MEMORY_BYTES'
    /
    
    

    Result:

    'DBVERSION'            DB_VERSION
    ---------------------- ----------------------------------------------------------------------------
    DB Version             11.2.0.1.0
    Oracle Client          64-bits
    Database Edition       Enterprise Edition
    Single Instance or RAC Single Instance
    No of CPUS             4
    No of CPU Cores        2
    No of CPU Sockets      1
    Physical Memory (GB)   3.864
    
    
    8 rows selected.
    
    

    Expected result:

    DB VERSION  ORACLE CLIENT   DATABASE EDITION         SINGLE INSTANCE OR RAC     NO OF CPUS  NO OF CPU CORES  NO OF CPU SOCKETS  PHYSICAL MEMORY (GB)
    ----------- --------------- ------------------------ -------------------------- ----------- ---------------- ------------------ ---------------------
    11.2.0.1.0  64-bits         Enterprise Edition       Single Instance            4           2                1                  3.84
    
    

    Any help would be greatly appreciated.

    Val

    SELECT "DB Version."

    "Oracle Client."

    "Database Edition."

    "Single instance or RAC.

    "None of the processors."

    "No CPU Cores.

    "No CPU Sockets."

    "Physical memory (GB).

    OF (choose the version "DB Version" of v$ instance where rownum)<>

    (choose the length (addr) * 4 | bits "Oracle Client" from v$ process where ROWNUM = 1).

    (select trim (substr (banner, 20: 19)) "Database Edition" version $ v where rownum)<>

    (select CASE COUNT (1) WHEN 1 THEN 'Single Instance' ELSE 'RAC' END 'Single Instance or RAC' SGS $ instance).

    (SELECT to_char (value) 'Number of processors' v$ stat_name WHERE osstat = 'NUM_CPUS'),

    (SELECT to_char (value) "Number of CPU cores" v $ stat_name WHERE osstat = 'NUM_CPU_CORES'),

    (SELECT to_char (value) 'number of CPU Sockets"v$ stat_name WHERE osstat = 'NUM_CPU_SOCKETS'),

    (SELECT to_char (ROUND ((value/1024/1024/1024), 3)) 'physical memory (GB)' v $ stat_name WHERE osstat = "PHYSICAL_MEMORY_BYTES")

    /

    DB Version Oracle customer Database Edition Single Instance No. No. processors CPU Cores No. CPU Sockets physical memory (GB)
    ----------------- --------------- ------------------- --------------- ---------- --------------- ----------------- --------------------
    11.2.0.3.0 64-bit Enterprise Edition Single Instance 4 4 and 1 7.991

    SQL >

    SY.

  • Skip and capture the Oracle SQL record dirty in a select statement

    Hello

    I have the Oracle Oracle 11.2.0.4 database when I run a select query.

    Question:

    10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.

    Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error

    OK, you have several TO_DATE functions fed a string that is built on the fly.  At least part of the time, the chain that is built does not match the date format mask used.

    For example:

    TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")

    "SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12.  You'll have to do an analysis on this column.  From its data and how that is managed by to_char.  What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?

    As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second).  ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.

  • DDL lock on the object in a SELECT statement?

    Environment:

    Oracle 11.2.0.4 EE on Solaris

    My client called me when she was trying to create a new index on a table and the process was just hanging.  Also, she was not able to DELETE an existing index on the same table, which deal with hang them as well.

    After reviewing the advice DBA_DDL_LOCKS, I found a DDL lock on the target of the index table.

    The DDL lock is held by a process doing a SELECT on the table and this process worked for several hours.

    There was no entry in V$ LOCKED_OBJECTS for the table.

    I don't know, yet, what other operations prior to the SELECT statement in the offending process, I have not heard of the user yet.

    I realize a DDL lock is placed on objects to prevent changes while specific operations are directed against this object, i.e. the DROP, UPDATE, compile the PACKAGE, etc.

    Question: Is a select also place a DDL lock on a table at a level that would avoid a new index is created or an existing index having fallen?

    Thank you very much for your comments!

    Any reference to the resolution is greatly appreciated.

    I searched some Concepts Developers Guide, SQL, even Google reference Guide.

    -gary

    > My question is now, this lock persists for the duration of the running query?

    Easy enough to show that it is not.

    Session1:

    SQL> create table foo(bar number);     
    
    Table created.                         
    
    SQL> insert into foo values(1);       
    
    1 row created.                         
    
    SQL> commit;                           
    
    Commit complete.                       
    
    SQL> variable x refcursor
    SQL> variable a number
    SQL> begin
      2  open :X for select bar from foo;
      3  end;
      4  /                                 
    
    PL/SQL procedure successfully completed.
    

    Session 2:

    SQL> drop table foo;
    
    Table dropped.     
    

    Note that I was able to remove the table even if select is still 'in progress' - the cursor is open.

    If you really want to blow your mind, go back to the session 1:

    SQL> begin
      2  fetch :X into :a;
      3  end;
      4  /                                
    
    PL/SQL procedure successfully completed.
    
    SQL> print a                          
    
             A
    ----------
             1       
    

    The picture has gone, but I can always look for him. However, try again:

    SQL> /
    begin
    *
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00942: table or view does not exist          
    

    Note that the forum software is stupid. is: followed by x. seems it's really important to have a smiley to lovey eyes in a technical forum.

    Edit - and when you format the SQL code, it is removed completely and render invisible... silly.

    I edited my code to use: X and the problem disappeared...

  • Invalid identifier on the Select statement

    New to SQL. I'm having some trouble with a function.
    Assignment is:
    1. develop and execute a CREATE FUNCTION statement to create the DAY_ORD_SF function. Use the column DTCREATED table bb_basket as the date that the basket was created. Call the function TO_CHAR using the option of the DAY to extract the day of the week for a date value.
    1. create a SELECT statement that lists the basket id and the day of the week set for each basket.
    3. create a SELECT with a GROUP BY clause query to list the total number of baskets by day of the week. Who is the most popular of a day shopping? (Should discover that it is FRIDAY).

    So far, I have the function:
    CREATE OR REPLACE FUNCTION DAY_ORD_SF (P_ORDER_DATE IN BB_BASKET.DTORDERED%TYPE)
     RETURN VARCHAR2
     IS
       LV_DAY_WK VARCHAR2(3);
    BEGIN
     SELECT TO_CHAR(P_ORDER_DATE, 'DAY') 
      INTO LV_DAY_WK
      FROM BB_BASKET
      WHERE P_ORDER_DATE = DTORDERED;
     RETURN LV_DAY_WK;
    END;
    /
    Have you tried a select invalid identifier and get on o_dt. have you tried several different variables and impossible to find one that works.
    SELECT DAY_ORD_SF(O_DT) "DAY", COUNT(*)
    FROM BB_BASKET
    GROUP BY DAY_ORD_SF(O_DT)
    ;
    Any help would be appreciated.

    >
    DTCREATED is a column name in the table BB_BASKET. When I pass O_DT to DTCREATED, I get an error:
    >
    So track what causes this error. Your instructions were to use DTCREATED.

    You use this query in your service

    SELECT TO_CHAR(P_ORDER_DATE, 'DAY')
      INTO LV_DAY_WK
      FROM BB_BASKET
      WHERE P_ORDER_DATE = DTORDERED;
    

    And the error tells you that LV_DAY_WK is too small. Why is it too small? Look at how it is defined and then look at the results of this query

    SELECT TO_CHAR(DTCREATED, 'DAY')
      FROM BB_BASKET
    

    and see if you can see what the problem is.

    You do your development backward. Failed to start by trying to call a function that does not work. And you can't start by writing a function that includes queries that have not been tested.

    The right way to generate code is to create simple components. Then test these simple components (for example a query) to ensure they work. Then mix the simple components in a component more complex as a function. Then, you can test the function of another request call.

    The key is to start with simple things that work.

  • Create table as select statement (ETG) takes a long time.

    Hi all

    One of my procedure launched a table create as select statement each month.
    Usually it ends in 20 minutes. for 6172063 records and 1 hour in 13699067.
    But this time it never even takes to 38076 records.
    When I checked everything he does is the CPU usage. No e/s.
    I did a count (*) using the query, it has brought very good results.
    BUT guard going on DEC.
    I use Oracle 10.2.0.4.
    temp_ip of the main table has 38076
    table nhs_opcs_hier has 26769 records.
    and table nhs_icd10_hier 49551 records.
    -------------------
    Query is:
    create the table analytic_hes.temp_ip_hier as
    Select b.*, (select nvl (max (hierarchy), 0))
    of ref_hd.nhs_opcs_hier one
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_PROCEDURE, secondary_procedure_1, secondary_procedure_2,
    secondary_procedure_3, secondary_procedure_4, secondary_procedure_5,
    secondary_procedure_6, secondary_procedure_7, secondary_procedure_8,
    secondary_procedure_9, secondary_procedure_10,
    secondary_procedure_11, secondary_procedure_12)) as hd_procedure_hierarchy,
    (select nvl (max (hierarchy), 0) for ref_hd.nhs_icd10_hier one)
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_diagnosis, secondary_diagnosis_1,
    secondary_diagnosis_2, secondary_diagnosis_3,
    secondary_diagnosis_4, secondary_diagnosis_5,
    secondary_diagnosis_6, secondary_diagnosis_7,
    secondary_diagnosis_8, secondary_diagnosis_9,
    secondary_diagnosis_10, secondary_diagnosis_11,
    secondary_diagnosis_12, secondary_diagnosis_13,
    secondary_diagnosis_14)) as hd_diagnosis_hierarchy
    of analytic_hes.temp_ip b
    -----------------

    Any help would be greatly appreciated

    Hello

    It is a bit of a wild card, I think because it will require 14 scans to fill the table temp_ip to unpivot codes diagnostic and procedure, so this lilkely things are moving slower than the original. However, as it is a temporary table, I guess you could have some control over its structure, or at least be able to dismiss it and try something else. If you are able to change the structure of this table, you could make the application much simpler and probably much faster. I think that you need a list of codes of procedure for the year and a list of diagnosis for fiscal codes. I do this through the large list of UNION all THE INSTRUCTIONS, but you can have a more efficient way to do according to the base tables you are people temp_ip of. In any case, it's here (as far as I can tell this will do the same job)

    WITH codes AS
    (   SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            primary_PROCEDURE       procedure_code,
            primary_diagnosis       diagnosis_code,
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_1    procedure_code,
            secondary_diagnosis_1    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_2    procedure_code ,
            secondary_diagnosis_2    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_3    procedure_code,
            secondary_diagnosis_3    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_4    procedure_code,
            secondary_diagnosis_4    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_5    procedure_code,
            secondary_diagnosis_5    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_6    procedure_code,
            secondary_diagnosis_6    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_7    procedure_code,
            secondary_diagnosis_7    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_8    procedure_code,
            secondary_diagnosis_8    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_9    procedure_code,
            secondary_diagnosis_9    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_10  procedure_code,
            secondary_diagnosis_10    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_11  procedure_code,
            secondary_diagnosis_11    diagnosis_code
        FROM
            temp_ip
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_12  procedure_code,
            secondary_diagnosis_12    diagnosis_code
        FROM
            temp_ip
    ), hd_procedure_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_procedure_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_opcs_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.procedure_code
        GROUP BY
            a.fiscal_year
    ),hd_diagnosis_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_diagnosis_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_icd10_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.diagnosis_code
        GROUP BY
            a.fiscal_year
    )
    SELECT b.*, a.hd_procedure_hierarchy, c.hd_diagnosis_hierarchy
      FROM analytic_hes.temp_ip b,
           LEFT OUTER JOIN hd_procedure_hierarchy a
              ON (a.fiscal_year = b.hd_spell_fiscal_year)
           LEFT OUTER JOIN hd_diagnosis_hierarchy c
              ON (c.fiscal_year = b.hd_spell_fiscal_year)
    

    HTH

    David

  • creating a table from a select statement

    is it possible to run a select statement that creates a table based on the statement of execution? in MSSQL I can include 'in {tablename}"in a select statement and it will automatically create the table field names / on the fly?

    I know I can run "insertion in {tablename} select * from foo" to fill an existing table, but I want something that creates the table as well.
    create table 
    as select ...
    

    Is that what you are looking for?

    Nicolas.

  • Select statements

    Hey,.
    I am new to use apex 4.0 and I am trying to create a select statement and I get an error. The error is
    "ORA-01427: einreihig subquery returns more than one line.

    My select statement is:

    Select * from XXMFG_CHANGE_FORM_SIGNOFF where item_number = (select item_number XXMFG_CHANGE_FORM_master where final_signoff_value IS null)

    Thank you

    Swens,

    I bet that if you ran

    select item_number from XXMFG_CHANGE_FORM_master where final_signoff_value IS null
    

    in the SQL workshop, you get several results back. This is what means this error. So you need to either set your logic to return a single element or change your = a in. It depends on what you want your code to do.

    select *
    from XXMFG_CHANGE_FORM_SIGNOFF
    where item_number in (select item_number from XXMFG_CHANGE_FORM_master where final_signoff_value IS null)
    

    Whatever it is, it is a problem SQL, not an APEX one.

    -David

  • How to use the Type of Oracle Table values in the Select statement.

    Hello

    I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.

    For example, try something like the following:

    TYPE t_record () IS RENDERING
    ID TABLEA.ID%type,
    NO TABLEA.NO%type

    );
    v_record t_record;
    T_table TYPE IS the v_record TABLE % TYPE;
    v_table t_table;

    -Code to fill the values of v_table here.

    SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
    WHERE ID IN (i) v_table USER.USER;

    I want to know how to use the Type of Oracle Table values in the Select statement.

    Something like this:

    create or replace type t_record as  object (
    id number,
    no number
    )
    /
    
    CREATE or replace type t_table AS TABLE OF t_record;
    /
    
    set serveroutput on
    declare
    
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    
    begin
    
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
    
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
    
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
    
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /
    

    No test!

    P;

    Published by: bluefrog on March 5, 2010 17:08

  • Need help with the update with several joins statement

    I have the following select statement, which takes 29 records:
    SELECT
    PAA. PROJECT,
    PAA. SEGMENT1,
    PEIA.expenditure_item_id,
    PEIA.expenditure_type,
    PEC.expenditure_comment
    OF PA.PA_PROJECTS_ALL APP.
    PEIA PA.pa_expenditure_items_all,
    PEC PA.pa_expenditure_comments
    where PPA.segment1 < '2008' and
    PPA.project_id = 52 and - just run for project # 20077119 for the test
    PEIA.expenditure_type = 'PAY' and
    PEIA.project_id = ppa.project_id and
    PEC. EXPENDITURE_ITEM_ID = PEIA. EXPENDITURE_ITEM_ID;

    I need to update the pec.expenditure_comments to a static field for 29 records. I guess I should start with the following, but don't know how to fill in the where:
    Update
    PEC PA.pa_expenditure_comments
    Set pec.expenditure_comment = ' REFERENCE HD #728'.
    where
    ???

    First time we have ever needed to update, so any help appreciated.

    Try using are:

    update pa.pa_expenditure_comments pec
    set    pec.expenditure_comment = 'REFERENCE HD#728'
    where exists ( select null
                   from   pa.pa_projects_all ppa
                   ,      pa.pa_expenditure_items_all peia
                   ,      pa.pa_expenditure_comments pec2
                   where  ppa.segment1 < ''    -- not sure what you posted here, so for next time:
                                               -- please put your examples between the code tags.
                   and    ppa.project_id = 52  -- just run for project # 20077119 for testing
                   and    peia.expenditure_type = 'PAYROLL'
                   and    peia.project_id = ppa.project_id
                   and    pec2.expenditure_item_id = peia.expenditure_item_id
                   and    pec2.expenditure_item_id = pec.expenditure_item_id
                 );
    
  • Return multiple values from a function in a SELECT statement

    I hope I've provided enough information here. If not, let me know what I'm missing.

    I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).

    Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.

    For example, right now, I have:

    Table 1:
    sequence_number NUMBER (10),
    name varchar (30),
    ...

    Table2:
    Table1_seq NUMBER (10),
    action_seq NUMBER (10),
    action_date DATE,
    action_office VARCHAR (3),
    action_value VARCHAR (60),
    ...

    I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.

    The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
    CREATE VIEW all_this_stuff AS
    SELECT sequence_number, name,
    RP.action_date (sequence_number) action_date,
    RP.action_office (sequence_number) action_office,
    RP.action_value (sequence_number) action_value
    FROM table1

    Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?

    Any suggestions?

    Thank you very much!

    Hello

    What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:

    WITH     got_rnum     AS
    (
         SELECT     action_seq, action_dt, action_office, action_type, action_value
         ,     ROW_NUMBER () OVER ( ORDER BY  action_date
                                   ,            action_seq
                             ,            action_serial
                           ) AS rnum
         FROM     table2
         WHERE     action_code     = 'AB'
         AND     action_office     LIKE 'E'     -- Is this right?
    )
    SELECT     action_seq, action_dt, action_office, action_type, action_value
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    

    As written, this returns a single line (at most).
    I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
    In this case, add a PARTITION BY clause to the ROW_NUMBER function.
    If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
    As I don't have your tables, I'll show you the use of the tables in the scott schema.
    This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.

    CREATE OR REPLACE VIEW     senior_emp
    AS
    WITH     got_rnum     AS
    (
         SELECT     d.deptno
         ,     d.dname
         ,     e.empno
         ,     e.ename
         ,     e.hiredate
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.deptno
                                   ORDER BY          e.hiredate
                             ,                e.empno
                           ) AS rnum
         FROM     scott.dept     d
         JOIN     scott.emp     e     ON     d.deptno     = e.deptno
    )
    SELECT     deptno
    ,     dname
    ,     empno
    ,     ename
    ,     hiredate
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    
    SELECT     *
    FROM     senior_emp
    ;
    

    Output:

    .    DEPTNO DNAME               EMPNO ENAME      HIREDATE
    ---------- -------------- ---------- ---------- ---------
            10 ACCOUNTING           7782 CLARK      09-JUN-81
            20 RESEARCH             7369 SMITH      17-DEC-80
            30 SALES                7499 ALLEN      20-FEB-81
    

    Moreover, one of the conditions to the query you posted has been

    action_office     LIKE 'E'
    

    which equals

    action_office     = 'E'
    

    (AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
    Did you mean say that or did you mean something like this:

    action_office     LIKE 'E%'
    

    Instead?

  • select statement difficult.

    Here's one I played with but am a bit stuck. This isn't really the scenario that I'm coding but it's similar.

    Think about a college you have students register for classes and a limited number of classes, but in addition it is a rule of fairness of dormitory in force
    I'll give you an example

    English 101 a 21 seats available.

    dorm 'A' has 1 student who wants to take the class
    dorm 'B' has 10 students who want to take the class
    dorm 'C' has 10 students who want to take the class
    dorm would be ' 10 students who want to take the class.
    'E' dorm has 10 students who want to take the class

    the result set should be 20 ranks
    dorm 'A' Gets a single class and dormitory B - E each get 5 classes of all out of luck.

    I've been playing with the dense rank function and the clause type but her I kinda stuck it that someone has suggestions how to attack this problem
    as a select statement? for the moment, it is a pl/sql stored procedure, but it would be cool to do a SQL statement without any pl/sql constructs.

    Hello

    If this is not a lottery, then put your selection criteria in the places where I used dbms_random.value.

    For example, if ADAMS, SMITH, JAMES and MILLER are all committed, and we have only shared 2 CLERKs, how do you chosose including two that is? I have assumed that it was random, but if you want to order by hiredate, sal, or anything else, that put in place dbms_random.

    It goes the same for the second lottery. Say that we have 7 seats to fill and 5 jobs. After the people of numbering for each job, we can refine the selection to 9 finalists (2 of each of the 4 jobs and 1 of employment which has only one person). We must take on the 4 2 jobs to have both of their admitted finalists, but how do we choose which 2? I have assumed that it was random, but if you want to classify the jobs according to the total number of people in work, or the hirdate of the applicant, or any other thing, then use it instead of dbms_random.

Maybe you are looking for

  • I do not see my faivorite tabs...

    I have firefox open today and I cannot see my tabs... How to change this back?

  • Why the same photo's file size different in Photos and in the Finder?

    I have a photo size 4608 x 3456. When I open the file information in the Apple's Photos app, it says that the file is 7.8 MB. When I open the same photo in the Finder and look at the news file, it is said that it is 3.1 MB on the disk. Why does this

  • Satellite L500-1XZ - cannot find any drivers

    I searched a lot of drivers, but I can't find the driver for: ACPI\TOS1900\2 & DABA3FF & 2 I have Windows 7 and in the control Panel\Hardware and the Sound\Devices and printers, laptop point of exclamation. Another problem I have is that the F8 funct

  • Readers uncertified casting flaws

    Hello We have a number of blades Dell Perc h700 and h710 Perc cards running. Most of them is running 840 Samsung pro SSDS and disks SSD Samsung 830 - these discs work perfectly well and we show him simply as "uncertified" and table is Non-critical",

  • EOP printer should not be default, possible?

    Hello We have activated EOP printer for the userers who access it via the Web portal remotely or at home. EOP printer works fine, when they connect to the default printer home House is also a default printer in the vdi. but when the user returns to t