AS the question of the clause with Group By

Hello everyone. I have a simple query that calculates the number of 3 expressions. It is supposed to cluster by region and province as well, but is rather the TOTAL number for each expression in the areas of the region and the province. What I am doing wrong? This is my query:

SELECT TABLE1. Province. "
TABLE1. "' Region '.
(SELECT (COUNT (TABLE1." "" 'Nationality')) "
FROM TABLE1
WHERE (TABLE1. "' Nationality ' <>'United States '.
AND TABLE1. ("' <>"Nat1"nationality")
OR (TABLE1. "" Medical <>""MEDICAL SUR ".
AND TABLE1. ("" <>Region ""CONUS")
) "TCN COUNT."
(SELECT (COUNT (TABLE1." "" 'Nationality')) "
FROM TABLE1
WHERE (TABLE1. ("' Nationality ' = 'United States')
OR (TABLE1. "" Medical <>""MEDICAL SUR ".
AND TABLE1. ("" <>Region ""CONUS")
) "US COUNT."
(SELECT (COUNT (TABLE1." "" 'Nationality')) "
FROM TABLE1
WHERE (TABLE1. ("" Nationality "="Nat1")
OR (TABLE1. "" Medical <>""MEDICAL SUR ".
AND TABLE1. ("" <>Region ""CONUS")
) 'HCN COUNT. "
FROM TABLE1
GROUP BY TABLE1. "" Province. "
TABLE1. "" Region ";

Any help would be appreciated. Thank you.

Aqua

Because you spend not all values of the inner query to external...

Are you looking for this?

SELECT      TABLE1."Province",
     TABLE1."Region",
     sum (
       case when (
             TABLE1."Nationality" != 'United States'
             AND TABLE1."Nationality" !=  'Nat1'
              )
            OR (
            TABLE1."Medical" != 'ON MEDICAL'
            AND TABLE1."Region" != 'CONUS'
             ) then 1 else 0 end
         ) "TCN COUNT",
     sum (
       case when (
            TABLE1."Nationality" = 'United States'
              )
            OR (
            TABLE1."Medical" 'ON MEDICAL'
            AND TABLE1."Region" 'CONUS'
                ) then 1 else 0 end
         ) "US COUNT",
     sum (
       case when (
            TABLE1."Nationality" = 'Nat1'
               )
              OR (
               TABLE1."Medical" 'ON MEDICAL'
               AND TABLE1."Region" 'CONUS'
                 ) then 1 else 0 end
         ) "HCN COUNT"
FROM TABLE1
GROUP BY TABLE1."Province",TABLE1."Region";

Tags: Database

Similar Questions

  • in the clause with subquery in oracle

    Hi friends,

    I have two tables say table1 and table2 with details below

    create table test1 (identification number, name varchar2 (20));
    Insert into test1 values(11,'micro');
    Insert into test1 values(22,'soft');


    create table test2 (identification number, name varchar2 (20));
    Insert into test2 values(77,'micro,soft');

    (1) if I use under request I do not receive either delivering lines
    Select * from t1 test1 where t1.name in (select "': replace (t2.name, ','" ', "') |") ' from test2;

    (2) if I had the fire out one subquery I get is: "micro", "smooth".
    Select "' | Replace (t2.name, ',' "'," ') | " ' from test2;

    But if I fire the query (1) I need the result
    name identity
    ------------
    11 microphone
    22 soft

    can someone please help me to get the same result with a query (1).

    Few things

    1. your table TEST2 is not in first normal form (1NF). It's ugly!

    2. IN paragraph does not evaluate a single variable or a column with values defined as several values, they are just single value.

    FAQ a few details, read Re: 7. the list of values in an IN clause?

    And this is how its done (one-way)

    SQL > select id, name
    test1 2
    3 where name in)
    4 Select regexp_substr (name, "[^,] +', 1, level")
    5 of test2
    6 where id = 77
    7. plug
    8 per level<= length(name)-length(replace(name,="">
    9                 );

    ID NAME
    ---------- --------------------
    11 microphone
    22 soft

  • the clause WITH XMLNAMESPACES xmltable: do you go on the internet for xsd?

    Hello

    I have a request of xmltable passing an xmltype variable.

    Something like this:
    select id, name, data
    From XMLTable(XMLNamespaces ('https://www3.somesite.es/bla/bla/bla/thexsd.xsd' as "n1" , 
                                        'https://www3.somesite.es/bla/bla/bla/otherxsd.xsd' as "co") , 
                         '/n1:some/tag' passing l_my_xmltype_var 
    COLUMNS id        NUMBER(20)      PATH '//n1:id' ,
                                 name        VARCHAR2(9)     PATH '//n1:name' ,
                                 data     VARCHAR2(125)   PATH '//co:datatxt') X
    This query is executed in a loop, and we try to improve its performance.
    S/n told me that whenever the query is run, we need to get the two xsd via internet.

    1. is this true?
    2. If it is... Can I keep the local XSD or even inside the database? (I heard something on the registration of the scheme)

    Thank you

    Julius says:
    The actual query has more than 75 columns. Its consumption is spent on java, so I have to assume that this is because of the money the xmltable process analysis.

    You OR do something (horribly) wrong OR should move to a longer version of database great or equal to 10.2.0.3.x

    PLEASE post your version of the database (all figures!)

    Do you mean that, even working with a local xmltable passing a variable xmltype (not a structured xml real chart), save the scheme will do good performance?

    Yep, for example by avoiding calls JAVA... through the registered XML schema validation is optimized if not only because of its kernel code, it's C - code

    I guess I have to:
    1 save the xsd
    2 reference him when I create the xmltype variable (by adding the second parameter to the function of xmltype).

    Fix.

    Then, during the treatment of xmltable, the engine will be smart enough to use the xsd saved info to improve the query performance? Okay, I'm a little skeptical, but will give it a try.

    I will also try to facilitate the processing by specifying the path of the full tree instead of using "/ / tag.

    It will make a difference (providing you're at least on 10.2.0.3.x regarding the use of XMLTABLE, the XQuery engine...)

    As a curiosity, all this quest for optimization of query came when - after a change - the performance of the query went from 5 seconds to 90 seconds. Things went south when I added a * in select it the list instead of referring columns with their names. So it doesn't seem a good idea to use * with a high column number xmltable

    Perhaps, but cannot say. These questions depend on many parameters and environment settings. It could be a connection problem or... or...

    It's one of the reasons why we need the version of database for you give a better answer...

    Published by: Marco Gralike June 8, 2011 11:17

  • Select the list with grouping

    Hi all

    I don't know that I remember seeing an apex somewhere plugin that has a selection list in a group by on her with. That is to say it would put the values of the selection into lettuces sections list. I tried this site Apex Plugin, but can't find it.

    Can someone point me in the right direction.

    Maybe I dreamed it.

    Shunt

    Hi, Shunt,

    Jarola made a post about this (if I understand correctly you want) - not a plugin in itself.

    See the Group Apex 3.2 select list

    Van
    Trent

  • Keep the layers with Group/Ungroup CS5

    I hope I missed a box hidden somewhere in illustrator.

    I work with complex figures and often use the group to move the sections and align the panels. Unfortunately, this process flattens all objects in a single layer; which is ok when I move the group, but NOT OK when I need ungroup and modify objects in layers separated again.

    For example:

    Graphic overlay, text, highlight behind the text.

    One use is when I make a model, distributing the work to occupy the available space, then going back in and update text and highlights, etc.

    I'm dealing with too many objects to manually reassign the layers after dissociation.

    Thank you.

    N ° this feature never existed in artificial intelligence and still does today. Layer affinity is not an attribute of the object, it's just the opposite, so any object that is grouped together with those on other layers is engulfed in the dominant layer, which is usually the first object belonged to.

    Mylenium

  • When the clause with conditions

    Hi all

    I have a report that must be filtered according to user input in a field of text and drop-down list.
    The goal is to let the user enter either an exact value (based on the AutoComplete feature) or use the wildcard character %

    It is where comes the menu drop down. If they choose value1, AutoComplete, the exact value is used and the where clause would look like something below,
    select col1, col2, col3
    from table
    where :P1_FILTER in (select distinct col2 from another_table)
    If they choose value2, then where should deal with using the same function and % s. something like:
    select col1, col2, col3
    from table
    where :P1_FILTER like (select distinct col2 from another_table)
    How can I take care of this in 1 where clause? I'm kind of stuck trying to figure out.
    Thanks for any help.

    -Chris

    Try this:

    select col1, col2, col3
    from table
    where
    (
    :P1_FILTER in (select distinct col2 from another_table)
    AND
    :P1_LOV =1
    )
    OR
    (
     :P1_FILTER like (select distinct col2 from another_table)
    AND
    :P1_LOV =2
    )
    

    I hope this helps!
    Sam

  • with the clause with union all?

    Hello

    I tried to use 'by' article with union all. .but it gives me error...
       with t1 as 
            (select '1'col1 from dual union all
             select '2' col2 from dual)select * from t1
             union 
            with t2 as 
            (select '3' col1 from dual union all
             select '4' col1 from dual )
              select * from t2
                
    What harm am I doing here? Thank you very much!!

    Use the WITH clause, once for you all the subqueries, and then add the main request;

    with t1 as
     (select '1' col1
      from dual
      union all
      select '2' col2
      from dual),
    t2 as
     (select '3' col1
      from dual
      union all
      select '4' col1
      from dual)
    select *
    from t1
    union
    select *
    from t2;
    
  • [SQL] Where the problem of the clause with subqueries

    Hello

    I am writing a query for an apex application where I have a field (P47_UNNR) for filtering. In my where clause I try to do this:

    ... AND IN qo.pk_id
    CASE
    WHEN: P47_UNNR IS NULL
    THEN
    (SELECT pk_id FROM quote_orders)
    ON THE OTHER
    (SELECT QOR. FK_QUOTE_ORDER_ID
    OF QUOTE_ORDER_RIDS QOR
    JOIN THE
    RID RID
    WE RID. PK_ID = QOR. FK_RID_ID
    WHERE RID.NAME LIKE: P47_UNNR)
    END
    ...


    But it gives an error "ORA-01427: einreihig subquery returns more than one line.

    I tried several ways to work around this problem, but don't seem to be able to do. Does anyone have a suggestion on how to fix this?

    Try something like...

    AND qo.pk_id IN
    (SELECT pk_id FROM quote_orders WHERE :47_UNNR IS NULL
     UNION ALL
     SELECT QOR.FK_QUOTE_ORDER_ID
     FROM   QUOTE_ORDER_RIDS QOR
            JOIN RIDS RID ON RID.PK_ID = QOR.FK_RID_ID
     WHERE RID.NAME LIKE :P47_UNNR
    )
    
  • Simple question, physical Mac associated with groups of ports to get hidden on switches?

    It's kind of hard to explain, but I'll try my best.  I just solved a problem related to the connectivity of the virtual machine with the network boys.  I provided them with the physical Mac associated VMNIC1 "00:18:FE:33:A4:47" I told them it was corrected in eight port.  When they logged on their switch they could not see at all, finally however when they tag with 208 port VLAN which is be one VM port groups configured with a virtual machine on that they were suddenly able to see the Mac of the VM that routes via VMNIC1 '00:18:FE:33:A4:47 '.

    For any reference later in order to learn and better understand things in the future can someone clarify how this works.  ESX hide/mask the physical Mac for Mac in the VM in this case, it was a former host ESX3.5 but I guess 5.5 would have done the same thing?

    Hello

    Welcome to the communities.

    I think that not only ESX hyper v too hide physical MAC and all VNIC have unique MAC id

    who play cluster type of role, the NETWORK load balancing configuration.

    Its my practical experience.

    ______________________________________________________________________

  • ORA-00907: lack the right parenthesis when using Group by clause with xmlagg

    I have the following query and I am getting ORA-00907 error when I use the clause with the xmlagg function group.
    select xmlelement("Mitigation",
                    xmlelement("m_szMethodName",tm.DisplayName),
                    xmlelement("SubstanceInterferenceProtocolList",
                                (select xmlagg(xmlelement("MitigationProtocol",
                                        xmlelement("m_szMethodName",tm.DisplayName),
                                        xmlelement("m_szInterferenceProtocolName",tmp.protocol_name),
                                        xmlelement("m_szInterferenceSubstance",tmp.intf_mtrl_prod_code),
                                        xmlelement("m_ProtocolParameters",
                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                xmlelement("m_Consumables",
                                                    xmlelement("Consumable",
                                                        xmlelement("m_szConsumId", xrl.rgnt_pack_name),
                                                        xmlelement("m_szProductCode",xrl.pack_prod_code),
                                                        xmlelement("m_nVolume",tmp.fluid_vol),
                                                        xmlelement("m_szProtocolStep",xps.protocol_step_name))),
                                                    xmlelement("m_ProtParamList",
                                                        xmlagg(
                                                        xmlelement("ParameterValues",
                                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                            xmlelement("m_Time",xpsd.parameter_ntime_value))
                                                        group by tmp.ccd_test_id,tmp.intf_mtrl_prod_code)
                    )))
                    order by tmp.ccd_test_id, tmp.intf_mtrl_prod_code, xps.protocol_step_intprotocolstep )
                    from XPR_tdef_mitigation_protocol tmp, xp_reagentlist xrl,
                    xpr_protocol_settings xps, xpr_protocol_settings_default xpsd
                    where tmp.ccd_test_id = tm.ccd_test_id
                    and tmp.ccd_test_id = xrl.ccd_test_id
                    and tmp.pack_prod_code = xrl.pack_prod_code
                    and tmp.intf_type = 1
                    and xps.protocol_name = xpsd.protocol_name
                    and xps.protocol_step_name = xpsd.protocol_step_name
                    and xps.ps_action_parameterlist = xpsd.ps_action_parameterlist
                    and xps.protocol_name =  tmp.PROTOCOL_NAME
                    )))
    from XPtoXPRTdef_defn_mapping tm
    where tm.DisplayName = 'SYPH'
    If I remove the clause xmlagg and the group by clause, the query works well and not give me the result.
    But in this code XML, the output format is incorrect for my application.

    Could someone help out here?

    Now my problem is that this unique coating is more than 32767 characters and utl_file can write 32767 bytes per line.
    Someone deal with this?

    Serialize the output as CLOB and DBMS_XSLPROCESSOR.clob2file procedure used to write to a file:

    DECLARE
      xml_output CLOB;
    BEGIN
      SELECT XMLElement("Department",
               XMLAgg(
                 XMLElement("Employee",e.job_id||' '||e.last_name)
                 ORDER BY e.last_name
               )
             ).getClobVal() AS "Dept_list"
      INTO xml_output
      FROM hr.employees e
      WHERE e.department_id = 30 OR e.department_id = 40;
    
      DBMS_XSLPROCESSOR.clob2file(xml_output, 'XML_DIR', 'test.xml');
    END;
    /
    
  • What is the significance of the CURSOR WITH HOLD clause in a cursor declaration?

    What is the significance of the CURSOR WITH HOLD clause in a cursor declaration?

    A cursor that has been declared with the clause WITH HOLD, after the word CURSOR remains open after a COMMIT or a ROLLBACK. The following example shows how to use the following clause:

         EXEC SQL          DECLARE C1 CURSOR WITH HOLD          FOR SELECT ENAME FROM EMP          WHERE EMPNO BETWEEN 7600 AND 7700      END-EXEC.
    

    The cursor must not be declared for the UPDATE. The WITH HOLD clause is used in DB2 to override the default, which is to close all cursors on validation. Pro * COBOL provides this clause in order to facilitate the migration of applications to DB2 to Oracle. When MODE = ANSI, use Oracle DB2 default, but all host variables must be declared in a declare Section.

    Reference:

    Oracle documentation!
    http://docs.Oracle.com/CD/B10501_01/AppDev.920/a96109/pco03dbc.htm

  • setWhereClause and ViewCriteria fail with an error in the original of the VO contains GROUP BY queries

    I have a display with a defined as query object:

    Select t.text, count (l.tag_id) as the use of tags t taglinks left outer join on t.id = l.tag_id inner join service_requests on l.svr_id = sr group of text sr.svr_id

    I am trying to allow a user to refine the displayed lines by providing additional search criteria.

    1. the approach with setWhereClause


    (contains thenewWhereClause '(sr.problem_description LIKE ' % machine % ") ' )

    this.setWhereClause (newWhereClause);
    this.executeQuery ();

    and it generates a new query as:

    Select t.text, count (l.tag_id) as the use of tags t taglinks left outer join on t.id = l.tag_id inner join service_requests on l.svr_id = sr.svr_id sr Group of text WHERE ((sr.problem_description LIKE '% machine %'))))

    (the problem is that the WHERE clause is behind the GROUP BY clause)

    2. the approach with ViewCriteria


    (the HashSet tgCrit contains a collection of strings)

    ViewCriteria vc = this.createViewCriteria ();
    ViewCriteriaRow vcr;
    Iterator;
    String value;
    It = tgCrit.iterator ();
    While (it.hasNext ()) {}
    value = (String) it.next ();
    VCR = vc.createViewCriteriaRow ();
    vcr.setAttribute ("Text", "LIKE" % "+ value +" %'");)
    vc.insertRow (vcr);
    }
    this.applyViewCriteria (vc);
    this.executeQuery ();

    and it generates a query such as:

    Select t.text, count (l.tag_id) as the use of tags t taglinks left outer join on t.id = l.tag_id inner join service_requests on l.svr_id = sr.svr_id sr Group of text WHERE (((TEXTE COMME: vc_temp_1)))

    (the same problem as before)

    The full background to the question is described in the other thread: Houston-27122 error after setWhereClause vo

    According to the previous thread, you disabled query package then this is the expected behavior (and is not caused by group by clause).

    The packaging of the query is prerequisite for a feature correct ViewCriteria because this allows framework generate something like: select * (your query) WHERE view_criteria_clauses.

    Dario

  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

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

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

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

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

    Lukasz

  • Why the books are grouped and preinstalled with the operating system?

    It's complaints

    My Portege has Windwosw Vista. I didn't want to buy Vista, but they were only selling with him and no other choice was possible to purchase.

    First of all, my laptop had problems to install Windows updates. I could not connect my institution's Internet System. I had to reinstall the system again.
    It's a waste of time!

    After re-installation of the button for the sound on the outside Panel does not work correctly.

    Also, when I try to stop the laptop sometimes it restarts itself - he doesn't stop!

    Secondly, I had a problem with the laptop, when an opportunity to visit a well-known site, it serves to block itself.
    Once, when he is blocked, I had to restart and its screen remained black. They took for repair. It was delivered later - repaired, but with a defect on the screen!
    What a... workers!

    When I bought this laptop he had an offer with the update of Vista with Windows 7 after their release.
    Wonderful. But just note, Toshiba has the highest price of the offer, compared to its competitors - 30 (or £) against 15 for others, which of course I'm not going to pay.

    I already paid for Vista, which is incredible, and I knew, but I had not choice not to buy!

    All right, so there is still competition in the market, several possibilities are present - install Windows cracked, switch to Linux or just buy an Apple!

    Please, take this comment seriously! And please, stop with group buying, no matter what the benefit is. It won't work for long.

    Hi mate

    Fact is that most of the laptop manufacturers sell the computer and laptop computer with a preinstalled operating system. So I wouldn't blame Toshiba or other brands for which

    You get a new computer/laptop with a new OS.
    During the past 20 years, Microsoft released 3.0 Win, Win 95, Win 98, Win NT, W2k, Win XP, Win ME, Vista and Win 7, I remember that all my computers or laptops were grouped with these operating systems

    Toshiba offers the notebook with a clean image and you can also create a recovery disk (so don t need to buy anything if you need t n)
    Of course, each of us can install a clean OS, but there are a lot of people who are happy with such image pre-installed because everything is pre-installed and configured.

    Many people have no knowledge of computer wide and are really recognizing that everything is pre-installed and the configuration does not have a lot of time

    With regard to the question of the laptop;
    What to say; you had a bad luck that something was wrong with the laptop. This can still happen that my new LCD TV other manufacturer, was dead after two weeks, I called ASP, then replaced the screen now is ok

  • window of 2008: ' I can't open Group Policy Management "group policy to manage, you must log on to the computer with a domain user account.

    Hi, please advise, I can't open Group on win Server 2008 policy management, it is said
    "To manage Group Policy, you must log on to the computer with a domain user account.

    Hi Cucu KurniaPutra,

    Thanks for asking this question to Microsoft Community!

    The problem occurs in Windows Server 2008 Network, please post your request on the Microsoft TechNet forums to get help.

    Here is the link:

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

    It will be useful. For any other corresponding Windows help, do not hesitate to contact us and we will be happy to help you.

    Kind regards!

Maybe you are looking for