Question about Group by

Hello friends,

I have a table called APPLICATIONS (INQUIRY_ID, CALLING_DATE, ASSIGN_TO_AGENT)

I need to create a report to show the number of requests received by Agent as follows:
Assign_to_agent , number_of_daily_inquiries, total_inquiries_number

X               ,         4                 , 150
Y               ,         8                 , 200
..........
....
I used this query that does not work:
select assign_to_agent   ,
 count (inquiry_id) , 
 (select count ( inquiry_id)   as "total_inquiries_number"
 from inquiries   where trunc ( calling_date,'DD' )= trunc ( sysdate, 'DD')  ) as "number_of_daily_inquiries"
from inquiries  group by assign_to_agent
I hope that my question was clear.

Kind regards
Water

Published by: cold_water on 25 Sep 2012 10:23

Hi cold_water,

Maybe it is not necessary to query two times table. Something like

select   i.assign_to_agent,
         count (
           case
             when trunc ( i.calling_date, 'DD') = trunc ( sysdate, 'DD') then
               i.inquiry_id
           end ) as "number_of_daily_inquiries",
         count (i.inquiry_id) as "total_inquiries_number"
from     inquiries i
group by i.assign_to_agent;

Concerning
Peter

Tags: Database

Similar Questions

  • Question about GROUP BY and double aggregation for example MAX (AVG (val))

    Good evening/morning,

    I am struggling with what is probably a simple problem.

    The objective of the exercise is to display the highest average earnings and his Department (with the EMP table).

    Easy to get the maximum average wage:
    select max(avg(sal)) as max_avg_sal
      from emp
     group by deptno;
    I could not figure out how to change this query to get the deptno associated AVG. max. Gave up on changing this query and came to this:
    select deptno,
           avg_sal as max_avg_sal
      from (
            select deptno,
                   avg(sal) as avg_sal
              from emp
             group by deptno
             --
             -- order causes 1st row to have the max(avg(sal))
             -- this will be exploited in the where of the outer query
             --
             order by avg_sal desc                                             
           )
     --
     -- get only the first row since that one has the values we want
     --
     where rownum <= 1;
    This works, but feels pretty disappointing compared to the simplicity of the first query (which I couldn't the deptno on.) That is the request more simple with that I could come.

    The QUESTION is:

    The query above is really the way simpler and easier to get the maximum average and its associated department number? If it isn't, I'm more interested in your simplest solution. :)

    Could someone to laugh at one of the alternatives that I came up with a "simpler": solution
    with x as
      (
       select deptno,
              avg(sal) as avg_sal
         from emp
        group by deptno
      ),
      max_avg_sal as
      (
       select max(avg_sal)                  as asmax
         from x
      ),
      deptno_max as
      (
       select deptno                        as dnmax
         from x where avg_sal = (select asmax from max_avg_sal)
      )
    select (select asmax from max_avg_sal) as max_avg_sal,
           (select dnmax from deptno_max)  as deptno_max
      from dual;
    The road to hell is simple, it is paved from selects < chuckle >,.

    Thank you for helping,

    John.

    Hello
    Try this

    SELECT MAX(AVG(sal)) AS max_avg_sal,
           MAX(DEPTNO) KEEP (DENSE_RANK FIRST ORDER BY AVG(SAL) DESC )  DEPTNO
    FROM scott.emp
    GROUP BY deptno
    

    Kind regards
    Anthony Alix

  • Question about grouping.

    Hello

    I have a problem with my data as I want, I have 2 tables: orders & Modifiedorders,.
    the Modifiedorders holds the orderid and some information on how the order is changed, sometimes orderid
    in the Modifiedorders table can repeat if the changed data are of different types, such as changing the quantity or the price...

    Now what I want is to make a report that displays data from the Orders table and when there is
    record (s) in the table modifiedorders that it should appear on the left, for example, but without repeating the orderid.

    What I tried creating a query of outerjoin between 2 tables and using the wizard I created a report with the style of left group and had Orderid as the grouping field, but again orderid. What should I do?

    Thanks in advance...

    What I tried creating a query of outerjoin between 2 tables and using the wizard I created a report with the style of left group and had Orderid as the grouping field, but again orderid. What should I do?

    You have made the right choice. Reuse the reports Wizard.

    What is your question?

  • questions about group by weeks

    Hello experts

    I have data similar to what follows below

    create the table t_one

    (

    sale number (30),

    date of date_req,

    req_desc varchar (1000)

    )

    insert into t_one values (30, to_date (March 7, 2014, ' DD/MM/YYYY'), 'boston')

    insert into t_one values (to_date 40, (March 9, 2014, "MM/DD/YYYY '"), "New York")

    insert into t_one values (10, to_date (March 14, 2014, ' DD/MM/YYYY'), 'boston')

    insert into t_one values (to_date 20, (March 16, 2014, "MM/DD/YYYY '"), "New York")

    required output

    Week total_sales

    Week 1-70

    Week 2 30

    Please note, the first week will start at 07/03/2014 in the system, that is why it is week 1 and a week is from (Friday - Sunday). That is because the execution is either on Friday or Saturday or Sunday. I have problems with this because I can't think of a good way to group my weeks together.

    any help is appreciated.

    Thank you

    Hello

    Here's one way:

    WITH got_week_num AS

    (

    Req_desc sale, SELECT

    , FLOOR ((date_req-TO_DATE (7 mars 2014 ", «MM/DD/YYYY»)))

    / 7

    ) + 1 AS week_num

    FROM t_one

    )

    SELECT 'week ' | week_num WEEK

    SUM (sales) AS total_sales

    OF got_week_num

    GROUP BY week_num

    ORDER BY week_num

    ;

    This will work with dates before March 7, 2014, also.  The week before week 1 (that is, the beginning of the week on February 28, 2014) week is 0; the week before this (from February 21) is week - 1 and so on.

  • question about group by function

    Hello

    I need to know why when the clause is not used, and the having clause is used in the function group, can any one will contact

    When the clause is used to filter the lines in service come pathological column.
    He selects and filters-out of the lines in the table listed in the from clause.

    for example if you have a table with matching employees and departments, and you want to see all employees of departments 10,20,30,40 and 50; you will use this condition in where clause

    select
        dept_id, emp_id
    from
        employee
    where
       dept_id in(10,20,30,40);
    

    Now let's say you want to check the number of employees in these departments

    select
        dept_id, count(emp_id)
    from
        employee
    where
       dept_id in(10,20,30,40)
    group by
       dept_id;
    

    now, if you need to select only the departments that have more than 1000 employees in them, your query will look like this:

    select
        dept_id, count(emp_id)
    from
        employee
    where
       dept_id in(10,20,30,40)
    group by
       dept_id
    having count(emp_id) > 1000;
    

    Here the condition where clause filters out all departments other than 10,20,30,40,50; the condition that must be applied for further filtering some departments on a per employee basis, cannot be applied in the where clause as it should be applied after + the function group worked on the rows of the table; After calculating the number of employees in each Department. Where the need for the clause which is evaluated after the group by the having clause.

    I hope this helps.

  • Question about GROUP BY and HAVING

    Good afternoon

    I have the following query, which returns the desired result (a set of students who follow the CS112 or CS114 but not both). I wanted to 'condense' it in a single SELECT statement (if that's possible - DDL of execution of the instruction is provided at the end of this post):
    --
    -- is this select distinct * and its associated where clause absolutely
    -- necessary to obtain the result ?
    --
    
    select distinct *
      from (
            select s.sno,
                   s.sname,
                   s.age,
                   sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end)
                     over (partition by s.sno) as takes_either_or_both
              from student s join take t
                               on (s.sno = t.sno)
           )
      where takes_either_or_both = 1
    ;
    The following text seemed reasonable, but unfortunately without success:
    /*
      Window functions not allowed here (in Having Clause)
    
    select max(s.sno),
           max(s.sname),
           max(s.age),
           sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) as takes_either_or_both
      from student s join take t
                       on (s.sno = t.sno)
     group by s.sno
    having sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) = 1
    ;
    
    */
    
    /*
    
    Invalid identifier in Having clause
    
    select s.sno,
           s.sname,
           s.age,
           sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) as takes_either_or_both
      from student s join take t
                       on (s.sno = t.sno)
     group by s.sno, s.sname, s.age
    having takes_either_or_both = 1
    ;
    I tried a document that completely defines the order in which the clauses are executed. I found bits and pieces here and there but not complete something. I realize that my race with problems like this is due to my lack of understanding of the sequence and scope of the clauses that make a statement. For this reason, I can't even say if it is possible to write the query above using a single select statement. Forgive my little frustration...

    Thank you for your help,

    John.

    DDL follows.
            /* drop any preexisting tables */
    
            drop table student;
            drop table courses;
            drop table take;
    
            /* table of students */
    
            create table student
            ( sno integer,
              sname varchar(10),
              age integer
            );
    
            /* table of courses */
    
            create table courses
            ( cno varchar(5),
              title varchar(10),
              credits integer
            );
    
            /* table of students and the courses they take */
    
            create table take
            ( sno integer,
              cno varchar(5)
            );
    
            insert into student values (1,'AARON',20);
            insert into student values (2,'CHUCK',21);
            insert into student values (3,'DOUG',20);
            insert into student values (4,'MAGGIE',19);
            insert into student values (5,'STEVE',22);
            insert into student values (6,'JING',18);
            insert into student values (7,'BRIAN',21);
            insert into student values (8,'KAY',20);
            insert into student values (9,'GILLIAN',20);
            insert into student values (10,'CHAD',21);
    
            insert into courses values ('CS112','PHYSICS',4);
            insert into courses values ('CS113','CALCULUS',4);
            insert into courses values ('CS114','HISTORY',4);
    
            insert into take values (1,'CS112');
            insert into take values (1,'CS113');
            insert into take values (1,'CS114');
            insert into take values (2,'CS112');
            insert into take values (3,'CS112');
            insert into take values (3,'CS114');
            insert into take values (4,'CS112');
            insert into take values (4,'CS113');
            insert into take values (5,'CS113');
            insert into take values (6,'CS113');
            insert into take values (6,'CS114');

    Hi, John,.

    Just use the SUM aggregate function.

    --
            select s.sno,
                   s.sname,
                   s.age,
                   sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end) as takes_either_or_both
              from student s join take t
                               on (s.sno = t.sno)
           GROUP BY  s.sno,
                    s.sname,
                  s.age
           HAVING  sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end)  = 1;
    

    Analytical functions are calculated after the WHERE - HAVING clause are applied. Use the results of an analytic function in a WHERE or HAVING clause, you need to calculate it in a subquery, and then you can use it in a WHERE - or the HAVING of a query clause Super.

  • Just a quick question about the appearance of the cluster

    Hello, this is Matthew, just a quick question about the appearance of the cluster

    Is there anyway to rearrange the order of the elements? I know cutting automatic resizing, I could move the items by hand. But if I use the cluster somewhere else, I have to move the items again...

    What I want is of the order of "Mx My Mz Ax Ay Az Temp voltage CS".

    Is there a quicker way to deal with?

    THz so much!

    You can right-click the border of the cluster and choose "arrange control cluster...". "The user interface is not as intuitive as it could be, but it will allow you to reorder items. If you use the cluster in several places, you should make the cluster in a type definition and replace all current uses of the latter with the type definition, so that they all match. They will also update automatically when you make changes to the type definition. Otherwise, you could have a situation where you have multiple groups with the same data types, but with elements in a different order, and your data will be getting a new denominated, when wire you the whole clusters. The data will be in the same order, but given that the item labels are in a different order, you can't get the data you want, when ungroup you by name.

  • The specific question about the placement of an image into text.

    Hello, I had a question about the placement of an image into text.

    I did the contours to create text to place the image inside. My text is 5 words and two lines inside the box.

    When I do create contours he gives me 2 transparent route separate layers for the top and the bottom line.

    How will I be able to do that in a single layer of compound to place image that expands to the two lines?

    First of all, there are two ways of describing the type. The default value creates anchored objects. You want a separate object, so hold down the Option/Alt key when you create outlines. Drag the new contours to separate the text block.

    It is useful to open the layers panel and view the contents of the layer. You have created a group which consists of two transparent traces. In the layers panel, expand the layer so you can see the structure. Shift-select the two transparent traces. (Make sure that the group is not selected.)

    Then choose object > tracks > make a compound path. This makes the two transparent tracks into one. Then, you can place or paste into the single compound path.

  • Questions about MRI

    Hi all

    My client asked me a few questions about MRI with ecm11g, I can't find the doc online answers, could someone tell me the answer?
    1. what kind of documents can be sealed by MRI, ms office should be able to be sealed, anyway, when I right click on a file .cmd or .rar in windows Resource Manager, there is no seal on in the option list
    2. is there a way to map IRM rights with model of account group/ECM ACL / security?
    3. text search full ECM can a doc sealed (for example: a word sealed) which is stored in ecm?

    Best regards

    I don't think that there is no configuration necessary.

    Just checked in 10g (Complutense University of MADRID and MRI):
    -There is a component called IRMIntegration
    -in the section of the Administration there is a menu item that allows configuration of base between the AAU and MRI (URL, port, etc) and it also contains an indicator "Index sealed Documents" - I think that it is the little thing that does not work in your system
    -When an element is integrated, it can be assigned to a metadata field called Protection MRI, which is filled with all the contexts in which a current 'seal' user allowed to (I assume that you do not see this area in your system)

    A context to this field of filling causes an item to be sealed. My system is a little slow, so I knew when the item was GENWWW, it was even made public. Once this was done, it was already sealed (and so was his web viewable format - spdf).

    I'll also take a look if the component is available in the 11g environment.

    As I expected: the component is not available in the 11g environment

    Edited by: jiri.machotka may 3, 2011 04:58

  • Question about DISCHARGE (expr, 1016) function

    Hello

    I have a question about the DUMP function, specifically the DUMP (expr, 1016). What character set is the function of report? The only logical answer seems to me the characters of data. The http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions055.htm#SQLRF00635 docs it says: "by default, the return value contains no character set information. To retrieve the name of character of expr, add 1000 to all the values of previous format. "For example, a return_fmt of 1008 returns the result in octal * and provides the character set name of expr.*.

    I ask this question because a client complains that there a database with database EE8MSWIN1250 (obtained from DATABASE_PROPERTIES) characters and when I asked him to run a SELECT that could empty the contents of a column, he gave me this result:
    select dump(some_col, 1016) from some_table;
    
    Typ=1 Len=8 CharacterSet=AL32UTF8: c5,bd,c5,a0,54,45,53,54
    Now I can't imagine how the data can be stored in the AL32UTF8 character set if the characters of the database are EE8MSWIN1250. This scenario is still possible? I tried in vain to reproduce on my test database.

    I don't know if the column is defined with the characters of database or the national database characterset, but even if it was a NVARCHAR2, the dump function could not return AL32UTF8 since he is not a national character set.

    If anyone has an explanation, I will be very grateful.

    Thanks in advance and best regards,
    Swear

    1. to help with the confusion about the DUMP function: index realizes that the DUMP function can be performed in the remote database. Oracle tries to push as many functions as possible and semantically correct on the remote site. Therefore, it sends the statement of simple table on the remote site after stripping the DB link. In this case, the DUMP function sees the character set of the remote database and creates the resulting string of information. This string of AL32UTF8 to EE8MSWIN1250, as described in the note, but as all the characters in the string of information are pure ASCII, some codes are actually changed.

    Things get more interesting if you start to combine the tables of local and remote databases. For example, the following query is will normally return the character of local database defined for the two columns:

    select dump(xx,1016),dump(yy,1016) from (select x.dummy xx, y.dummy yy from dual x, dual@dblink y);
    

    This is because the first dual@dblink is transported to the local site and the join is performed here with application of DUMP.

    The following query returns the set for two columns of characters in remote database:

    select dump(xx,1016),dump(yy,1016) from (select x.dummy xx, y.dummy yy from dual@dblink x, dual@dblink y);
    

    This is because all the tables are remote and the entire query is sent to the remote database and y.

    The following query returns the remote character set thus:

    select dump(xx,1016),dump(yy,1016) from (select /*+driving_site(y)*/ x.dummy xx, y.dummy yy from dual x, dual@dblink y);
    

    Here, the DRIVING_SITE hint asks the database to perform the join in the database of the table, for example dual@dblink.

    2. to answer your question:

    Your understanding of the way of conversion is generally correct, but conclusions are not quite correct. In the scenario [client EE8ISO8859P2, EE8MSWIN1250 local database, remote database AL32UTF8], Eastern and Central European characters will work correctly, but the other characters to the remote database will not be (for example, French, Greek, Chinese). It is, I think, quite clear and is usually not a major problem, as usually only compatible languages EE8 are interesting for an EE8ISO8859P2 customer. However, in the scenario [customer AL32UTF8, EE8MSWIN1250 local database, remote database AL32UTF8], the problem becomes more visible. Having a taking customer support Unicode, you can recover some data French or Greeks of the remote database but you will fail as all of these characters will be "killed" by the conversion of distance at the local level (link DB conversion).

    EE8ISO8859P2 is also for the same group of languages, such as EE8MSWIN1250, indeed, but it lacks some interesting characters. The most important of them is the symbol of the Euro. Others are "' quotes, long dashes, TM symbol, and a few other less frequently used punctuation. Therefore, always define a database as EE8MSWIN1250, even if you run some clients (Unix) with EE8ISO8859P2. Do not run Windows with EE8ISO8859P2 clients, except for purposes of loading/generation of special file.

    -Sergiusz

  • Several Questions about educational Versions of the software

    Well, I have several questions about teaching from Adobe software.  I will attend school in the near future (now I'm not enrolled in any type of school) and I see that Adobe has huge discounts on "educational software".

    What exactly is the difference between the "commercial" version of a program and an educational version?  Do you need some kind of student card to activate an educational version, or proof that you are in school, or something special like that?  I noticed people unopened sell educational versions on eBay and I heard there is no differences between the software, but this makes me wonder... why the price difference?

    Also, I intend on buying another Mac in the near future - probably for the school.  My second question is - with this software (education), is that I can put programs on my desktop and my laptop, or they won't work on one person on one computer?  I've heard people that serial numbers cannot be activated so many times.

    Last question.  My HDD recently crashed and I lost a good bit of things and had to re - install everything.  If this would never happen again, reinstall all Adobe programs on a hard drive nine?  Or I will meet the all 'serial numbers cannot be activated so many times?

    Very well.  I think about the fact.  Any input would be great.  Thank you.

    -Mike

    In terms of content, there normally is no real difference between the editions of the retail and educational/student. There may be some additional fonts or clip art in the commercial version, but this varies from one version to the other, and a product.

    You must qualify to buy an educational/student version. These qualifications are listed on the Adobe Web site. Normally, you must provide proof of reserve that sells licenses of software for you. You can not buy now for the reason that you will be a student in the future. You must have purchase student status.

    Unlike versions of retail, education/student Adobe versions software are not transferable. Sale of such software 'closed' on eBay must be regarded with suspicion. Adobe resellers do not offer software on eBay sales. The software is either stolen, used (but reconditioned), or pirated goods.

    Most of the Adobe software, including the Creative Suite software, can be activated at the same time on two computers owned and used by a single individual. second computer is usually a laptop, if first computer is a computer at home for students. For retail sales, usually first computer is a desktop computer and the second computer is a mobile computer or at home. Computers must not run the software at the same time. And No, two students may not share a single copy on two separate computers.

    The software can be turned on and off but after 20 or if these cycles, you will need to call Adobe and explain what is happening to get characters such cycles. If you are enabled on both systems and a hard drive or a computer turns off and you need to reinstall the software without having the possibility to disable the system blew, Adobe activation support group normally will be granted an additional activation, assuming that you do not have a record of abusing the privilege (as your hard drive breaks down once a month!).

    -Dov

  • A question about clusters

    Hello

    I have a question about the single table hash clusters. How are these paintings in a position to provide better performance? Any block can contain data from a single table, and here was the only cluster table will also create blocks with data from a table. So how or why is it more effective? I am not unclear on the concept plan and will be grateful for the info.

    Concerning

    Published by: orausern on 22 Sep, 2010 07:57

    orausern wrote:
    I did it - but the concept is what I'm looking for. The test case proves that there are benefits. but my question is why the profit returns. It's what I'm not very clearly.

    The benefit is provided
    (1) exercise you some control over the way in which the data are filled in the table
    2) most of your questions is a 'SELECT col1, col2,... '. "Col WHERE = "
    (3) the number of values unique 'col' is fairly constant
    The common approach in the situation described above is to create an index on 'col' so that applications may perform better.
    But even with the indexes in place, oracle will need to access the blocks of two segments, index and table, in order to process the requests (of the type described in step (2) above).
    When you create the table in a hash TABLE UNIQUE cluster, you can get the grouping of the data in the table itself, without the need of an index. Oracle will have access to the only segment (cluster) blocks to process requests (of the type described in step (2) above).
    The result is much less number of consistent gets for queries of the type described in step (2) above, resulting in better use of the buffer cache, which improves performance.
    I hope this helps.

  • Question about the Oracle database resource management

    Good evening
    I have a question about Oracle database Resource Management (DRM) for Oracle Database 10 g. I had an incident which, in a development/UAT environment (different instances, same box, don't ask), a developer wrote a wrong SQL statement that consumed 99% of the CPU. Currently, there is no limit of resources on two cases of db, and the developers don't want limits. However, my manager wants a method to prevent something like this does not happen. If I use the Oracle database resources management, create a consumer group (called "DevEnv") at 40% CPU usage, what will happen if a user of DevEnv runs a bad SQL statement that normally consumes 90% CPU again? Anyone would take a different approach? Thank you.

    Sincerely,
    Sho Fukamachi

    782718 wrote:
    If users in the case of "db_uat" use 60% CPU would be users who belongs to DevEnv pending 'db_test' cannot be used more than 40% CPU, so their queries become slower at their end? I would like to know if this behavior works the same in an environment of multiple instances. Thank you.

    Yes, because the available processor would be 40%, they use more, while.

  • Where can I ask a handful of general order questions about Firefox OS as a consumer and get the answers? (a forum or something similar)

    I have about seven questions about Firefox OS. I'm potentially interested in opting for a tablet that works instead of Android or iOS. I couldn't find a place to ask questions like that. Thank you!

    https://support.Mozilla.org/en-us/forums/Firefox-OS-English-Forum

    There is another option.

  • About a month ago I posted a question about iMovie and not being able to "share". I solved the problem thanks, so no more emails!

    About a month ago I posted a question about iMovie and not being able to "share". I solved the problem thanks, so no more emails!

    Hi Michael,

    If you want to stop receiving notifications by electronic mail, in the thread, that you have created, then I suggest that you follow the steps below:

    One time connected to the Apple Support communities, visit your mini profile and select manage subscriptions.

    Content

    To manage this content, you are currently subscribed and changing your preferences, select the content.

    Select next to see what content you are currently following.  Note that any thread you are responding you subscribe you automatically to this thread.

    You can select to terminate a subscription to a thread.

    Learn how to manage your subscriptions

    Take care.

Maybe you are looking for

  • black screen

    My screen phone blacked out on me a while back, I tried the House and power reset the thing but when my phone turns it fades again. Please I need answers.

  • Profile of Thunderbird is only partially recognized

    I have Thunderbird + Lightning in use on the operating systems Linux Mint and of Debian. Installation of Thunderbird Mint is used only for about six months after I switched to Debian as the main operating system. Debian installation encountered probl

  • Print spooler problem

    I'm not technical. I installed the drivers for a HP 1018 and was able to print. Now, I'm getting the print spooler error message. I have done repeatedly restarting the service etc. and can not get the impression of being recognized. The status of the

  • 2112 WLan controller and Point of access LAP1042n issue

    Hello I recently bought a 2112 a Wlan controller a number of LAP1042n Ap of the AP will not join the command and the message I get in the console of the AP, it is that the AIR-WLC2100-K9-6-0-199-4.aes firmware does not support this model?  Can someon

  • I receive you exit code 26 whille installing Master Collection from Adobe... Please help me!

    Please help me, I get you 26 exit code during product installation adobe Master Collection.Marleen greetings.