Select in group by

Hi Im trying to count the number of appointments we do by our situation so I have a nominations table and a table so sites when I execute this query, I get

a column with the date and the second column with one account, now I also wanted to include the contract number of site, but as that would not work with grouping I added a where clause, so I could then run it once for each site but when I add the contract_number of the where I lose the County.

Any help would be great Im new to oracle by Ive used mysql for years what I want to do is get a query were can I join two table via a contract_number (ID of SITE) and I want to group by date of appointment and returned 3 columns

the County and the contract_number and the date.

so I can show how much appointment each site had a date.

FIRST QUERY

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

Select TO_CHAR (APPOINTMENTS. APPOINTMENT_DATE_TIME, 'DD-MM-YYYY') as APPOINTMENT_DATE_TIME,

Count (DISTINCT from the appointment. SITE_ID) COUNTY

SITES SITES,

APPOINTMENTS APPOINTMENTS

where APPOINTMENTS. SITE_ID = SITES. CONTRACT_NUMBER

APPOINTMENT_DATE_TIME group

SECOND QUERY

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

Select TO_CHAR (APPOINTMENTS. APPOINTMENT_DATE_TIME, 'DD-MM-YYYY') as APPOINTMENT_DATE_TIME,

Count (DISTINCT from the appointment. SITE_ID) COUNTY

SITES SITES,

APPOINTMENTS APPOINTMENTS

where APPOINTMENTS. SITE_ID = SITES. CONTRACT_NUMBER AND SITES. CONTRACT_NUMBER = "MTNZ8013".

APPOINTMENT_DATE_TIME group

Hello

You have not yet published an insert for the sample data.  [#8 response was not up yet when I have all this.]

Apps4u wrote:

This is what is returned if you look at lines 2 and 3, they have the same date...

They have the same year, month and day.  Horodateurs Oracle (such as DATEs) include hours, miinutes and seconds as well (and horodateurs also have comments of a second).  You're not showing the hours, minutes, seconds, or fractions of a second; If you do (TO_CHAR is a way) you will see that the appoitment_date_times are slightly different.

...

Select trunc (APPOINTMENTS. APPOINTMENT_DATE_TIME) as APPOINTMENT_DATE_TIME,

SITES. CONTRACT_NUMBER,

Count (APPOINTMENTS.ID) COUNTY

SITES SITES,

APPOINTMENTS APPOINTMENTS

where APPOINTMENTS. SITE_ID = SITES. CONTRACT_NUMBER

APPOINTMENT_DATE_TIME group, SITES. CONTRACT_NUMBER

...

You have changed

appointment_date_time to

TRUNC (appointment_date_time) in the SELECT clause, but not in the GROUP BY clause.  You will need to change it in both places.

...

If I does not include the contract number I get the correct number

Select TO_CHAR (APPOINTMENTS. APPOINTMENT_DATE_TIME, 'DD-MM-YYYY') as APPOINTMENT_DATE_TIME,

Count (APPOINTMENTS.ID) COUNTY

SITES SITES,

APPOINTMENTS APPOINTMENTS

where APPOINTMENTS. SITE_ID = SITES. CONTRACT_NUMBER

APPOINTMENT_DATE_TIME group

APPOINTMENT_DATE_TIME COUNT
15/11/2015 2
15/11/2015 1
12/11/2015 1
15/12/2015 1
15/11/2015 1

Thus, line 1 has the date of 15/11/2015 and the number of 2, and I wish I had a 3rd column that contains the contract number.

Line 2 also has the date of 15/11/2015; then line 5.  Those are really the correct results, you may want to maybe if there is no GROUP BY the number of contract?  Would you like 3 separate rows for 15/11/2015 as the appointment_date_time?

Tags: Database

Similar Questions

  • How to select entire groups or to multiple recipients in MAIL, rather than one at a time?

    How to select entire groups or to multiple recipients in MAIL, rather than one at a time?

    One way is to use the app to create a group with the intended recipients. Then when composing the email just type the group name in the To: field.

  • How to select a group nested in the PS?

    When I use the self-select: Group option, it will select only the group most in which is placed my layer clicked; but I use a lot of groups nested inside other groups. Is there a way to change higher or lower level groups?

    Select the Group of lower level by clicking in the layers panel is tedious, because when I click on a layer with the value automatic selection 'Sex', it will automatically expand groups in which it is placed and I have to scroll up to find the layer group.

    Are you aware of the pop - up we get when ctrl-click with the tool move?

  • I can't select the groups in my outlook account

    under the head of the people, next to the used button it have a drop-down menu to select groups. but I'm unable to find these days.

    Hey Monty,

    Are you referring to Microsoft Outlook or Outlook.com?

    If you use Microsoft Office Outlook, then I suggest you according to the query in Microsoft Office Forum for better support.

    Reference:

    http://answers.Microsoft.com/en-us/Office/Forum/Outlook

    If you are referring to Outlook.com, then send the application in the Windows Live Forum for assistance:.

    Reference:

    http://answers.Microsoft.com/en-us/windowslive/Forum/mail

    I hope this helps. If you have any other queries/issues related to Windows, write us and we will be happy to help you further.

  • AnyConnect tunnel-group automatic assignment without selecting any group-tunnel-group-list alias and user-group strategy.

    Objective is that the anyconnect user must select group-alias, so that when a user enters his username and password he must go to his political group and tunnel-group specific. as I removed this command in webvpn 'no tunnel-group-list don't enable '. This I can not connect (user does not authenticate).

    1 - my question is why his past does not?

    Solution:

    If I keep only a single tunnel-group by default and make several group policies and assign to each user with his specific group policy that it works. in user attribute means I have only question following the commands it works, but if I put "group-lock value test-tunnel" that it did not identify.

    Please explain why.

    WebVPN

    allow outside

    limit the cache-fs 50

    SVC disk0:/anyconnect-win-3.0.10055-k9.pkg 1 image

    enable SVC

    internal strategy of group test-gp

    attributes of the strategy of group test-gp

    VPN-tunnel-Protocol svc webvpn

    the address value test-pool pools

    username, password test test

    username test attributes

    VPN-tunnel-Protocol svc

    group-lock value test-tunnel

    Strategy Group-VPN-test-gp

    tunnel-group test-tunnel type remote access

    attributes global-tunnel-group test-tunnel

    Group Policy - by default-test-gp

    tunnel-group test-tunnel webvpn-attributes

    allow group-url https://192.168.168.2/test

    Yes, you have the right solution. You only need to create 1 group of tunnel and multiple group policy. Under the attribute of the user, you re then group policy of vpn that you want the user assigned too.

    You can also authenticate users against AD and configure ldap attribute map to map the user to a specific group policy automatically.

    Here is an example of configuration if you happen to have the AD and will authenticate against AD:

    http://www.Cisco.com/en/us/products/ps6120/products_configuration_example09186a00808d1a7c.shtml

    Hope that helps.

  • Several repeating subforms that appear in the order of selection, not grouped.

    Hi all, I have a problem with the repetition of the subforms. In my form, I have several subforms which I want to have the option of repetition through buttons. The problem is I want appear them on the form in the order in which keys were pressed and not appearing in the groups apparently (for example. A subform subform B, Subform subform NOT to, subform A subform B)

    For example:

    -A subform

    -subform B

    -C subform

    Press the button A subform (related to the Action "Add a new instance of A subform") which makes this subform appear.

    Then do the same for the subform B.

    So if you want an another A subform appears I want it to appear in the sequence of those selected (eg. A, B subform, A subform subform) not A of A, B subform Subform subform.

    .

    Any help would be greatly appreciated.

    Hello

    I think the best idea would be to have each of these subforms in a subform.

    When an instance of the any of these subform are added, add subform instance of parent, and hide/show subforms good you wanted to add instances

    For example:

    -ParentSubform

    -SubformA (Hidden)

    -SubformB (Hidden)

    -SubformC (Hidden)

    (Add the instance to SubformA)

    _ParentSubform.insertInstance (ParentSubform.index + 1);

    xfa.resolveNode ("ParentSubform [" + (ParentSubform.index + 1) m:System.NET.SocketAddress.ToString () + "]" "). SubformA.presence = "visible";

    (Add the instance to SubformB)

    _ParentSubform.insertInstance (ParentSubform.index + 1);

    xfa.resolveNode ("ParentSubform [" + (ParentSubform.index + 1) m:System.NET.SocketAddress.ToString () + "]" "). SubformB.presence = "visible";

    (Add the instance to SubformC)

    _ParentSubform.insertInstance (ParentSubform.index + 1);

    xfa.resolveNode ("ParentSubform [" + (ParentSubform.index + 1) m:System.NET.SocketAddress.ToString () + "]" "). SubformC.presence = "visible";

    I hope this helps!

  • How to select the group header with detailed data in a SQL

    Dear Sir

    I wish I had a little help from you. My goal is to create a view where the data should be in the appropriate format. In this format, I want to have for each header of a group.

    I have 3 tables that they ar connected to the other (representing hierarchical data where financial plan breaks in different groups).

    CRM_PLAN
    CRM_PLAN_ID
    DATE
    AMOUNT

    CRM_PLAN_PE
    CRM_PLAN_PE_ID
    TITLE
    AMOUNT
    CRM_PLAN_ID (REF CRM_PLAN key. CRM_PLAN_ID)

    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID
    YEAR
    MONTH
    AMOUNT
    CRM_PLAN_PE_ID (foreign key to CRM_PLAN_PE. CRM_PLAN_PE_ID)

    Data looks like:

    CRM_PLAN
    CRM_PLAN_ID | DATE | AMOUNT
    1. 01.01.2012. 500
    2. 01.02.2012 | 200

    CRM_PLAN_PE
    CRM_PLAN_PE_ID | TITLE | AMOUNT | CRM_PLAN_ID
    1. Organization 1. 100. 1
    2. Organization 2. 400. 1
    5: 3 organization | 200 | 2


    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID | YEAR | MONTH | AMOUNT | CRM_PLAN_PE_ID
    1. 2012 | 1. 60. 1
    2. 2012 | 2. 40. 1
    5: 2012 | 1. 350. 2
    4. 2012 | 2. 50. 2
    3: 2012 | 1. 200 | 3


    I would like to than the view that returns data as:

    MONTH | AMOUNT
    Organization 1. null
    1. 60
    2. 40
    Organization 2. null
    1. 350
    2. 50
    3 organization | null
    1. 200

    The main question is hot to write a sql as source for display to insert before each group a line with the value of the title of the table CRM_PLAN_PE column. Is it still possible? Perhaps you could suggest another method.

    Notice will be used in the form of oracle where will be possible to change the data - I will make the necessary arrangements by trigger INSTEAD of.

    Kind regards
    Igor

    Published by: user5528050 on 29.11.2012 02:23

    Published by: user5528050 on 29.11.2012 02:24

    Published by: user5528050 on 29.11.2012 02:25

    Hi, Igor,.

    In this case, I think ROLLUP is a little simpeler GROUPING SETS, but you could do it anyway:

    SELECT       CASE
               WHEN  GROUPING (tab2.id) = 0
               THEN  TO_CHAR (tab2.id)
               ELSE  tab1.title
           END               AS col_1
    ,       SUM (tab2.amount)     AS col_2
    FROM       tab1
    JOIN       tab2     ON  tab1.id     = tab2.tab1_id
    GROUP BY  tab1.title
    ,            ROLLUP (tab2.id)
    ORDER BY  tab1.title
    ,         GROUPING (tab2.id)     DESC
    ,            tab2.id
    ;
    

    If tab2.id cannot be NULL, you can use

    NVL ( TO_CHAR (tab2.id)
        , tab1.title
        )
    

    instead of the CASE expression and simplify the ORDER BY clause to

    ORDER BY  tab1.title
    ,            tab2.id            NULLS FIRST          
    
  • Selection of group and the radio text box

    I have a form with a question like: "How did you who are we?" and a radio with some choice group. One of the radio group choice is "other - please describe! When selected, a text box changes to 'read only' and the user can write something. I'm not able to update a record with the user's selection in a field in a table (I can save either text or radio group selection area). Any help? Thank you!

    You should check the value of the selected option button. If it's not ' I have this answer: ", assign the value to $_POST ['Proposal_text'].

    If ((isset($_POST["MM_update"])) & ($_POST ["MM_update"] == "form1")) {}

    If ($_POST ['proposal']! = ' I have this answer: "") {}

    $_POST ['Proposal_text'] = $_POST ['proposal'];

    }


    $updateSQL = sprintf ("UPDATE sarcini SET solutie_6 = %s, introd_6 = %s WHERE id_question = %s",

    GetSQLValueString ($_POST ['Proposal_text'], "text").

    GetSQLValueString ($_POST ["'Full_name"], "text").

    GetSQLValueString ($_POST ['id_question'], "int"));

  • Select join + group of

    Hello
    is it possible to implement the quiery following in single statement:
    Select all the Hr.Countries.Region_ID, Hr.Regions.Region_name to all areas with > 3 countries table.
    I can do this with an intermediate temporary table but can't suddenly:

    Country: =.
    Country_ID
    country_name
    Region_ID (FK to regions)

    Regions: =.
    Region_id
    Region_name

    TX
    TR

    Like this?

    SELECT Region_ID, Region_name
      FROM regions r
     WHERE EXISTS
              (SELECT 1
                 FROM countries c
                WHERE c.region_id = r.region_id
               GROUP BY c.region_id
               HAVING COUNT (1) > 3)
    

    G.

  • Select all & group, scale Strokes & Styles via JavaScript?

    Hello

    I really wish the Forum search worked, because I'm sure that this issue has been addressed...

    (1) is there a way to access the selection > all (Ctrl + A) and object > Group (Gtrl-G) using JavaScript controls?

    If I was doing the process "in hand", I must select > all (Ctrl + A), group (Ctrl + G), create a new layer, cut (Ctrl + X) and paste (Ctrl + V).

    My first attempt to do this programagically had to loop through all the elements of the art and the method move() to move one by one in a new GroupItem on the new layer. However, the results questionable cases at best because of the variability in the amount of nested groups, composed of path elements, masks clipping, etc..

    So, I can probably get the feature select all by a loop through the objects of art and in implementing selected = true, but how can I get all those items in a single GroupItem all-at-once instead of one at a time?

    (2) once I have everything in a single GroupItem, I would like to re-group size. However, using the resize() does not offer an option to scale the contours and the effects, as you can see, when you go to object > transform > scale...

    Is it possible for a group with contours and effects scale lit via JavaScript?

    Thanks for the comments!

    No, JS can not play actions

    no calculation, race number of scale is also in percent

  • Help of the complex select query (Group by)

    Hello
    I am in need of your help to create a unique select query for the data in the table below and whose output requies. I use oracle 10g on RHEL 5 version.

    create table bustour (number of bussno (4), start_date date, number (2)) passenger;
    ALTER session set nls_date_format = "dd-mm-yyyy";
    insert into bustour values (4123, April 10, 2009 ", 20);
    insert into bustour values (4123, may 10, 2009 ", 25);
    insert into bustour values (4123, may 10, 2009 ', 18);
    insert into bustour values (4123, June 10, 2009 ', 15);

    insert into bustour values (6138, March 10, 2009 ', 16);
    insert into bustour values (' 6138, March 10, 2009 ", 19);
    insert into bustour values (6138, April 10, 2009 ', 22);
    insert into bustour values (' 6138, April 10, 2009 ", 13);

    insert into bustour values ("4123, July 10, 2009 ', 23);
    insert into bustour values (4123, August 10, 2009 ", 27);
    insert into bustour values (4123, November 10, 2009 ', 15);

    insert into bustour values (6138, may 10, 2009 ', 16);
    insert into bustour values (6138, may 10, 2009 ', 13);
    insert into bustour values (6138, may 10, 2009 ', 18);
    insert into bustour values (' 6138, may 10, 2009 ", 24);
    insert into bustour values (6138, July 10, 2009 ", 20);
    insert into bustour values (6138, August 10, 2009 ", 18);
    SQL> select * from bustour;
    
        BUSSNO START_DATE PASSENGERS
    ---------- ---------- ----------
          4123 04-10-2009         20
          4123 05-10-2009         25
          4123 05-10-2009         18
          4123 06-10-2009         15
          6138 03-10-2009         16
          6138 03-10-2009         19
          6138 04-10-2009         22
          6138 04-10-2009         13
          4123 07-10-2009         23
          4123 08-10-2009         27
          4123 11-10-2009         15
    
        BUSSNO START_DATE PASSENGERS
    ---------- ---------- ----------
          6138 05-10-2009         16
          6138 05-10-2009         13
          6138 05-10-2009         18
          6138 05-10-2009         24
          6138 07-10-2009         20
          6138 08-10-2009         18
    
    17 rows selected.
    
    I want query output as below :
    
    Bussno  start_date      end_Date   totalpassengers   maxpessenger  maxpassdate
    4123    04-10-09        06-10-09          78              25         05-10-09
    6138    03-10-09        04-10-09          70              22         04-10-09 
    4123    07-10-09        11-10-09          65              27         08-10-09
    6138    05-10-09        08-10-09         109              24         05-10-09
    So that we can know on what particular travel calendar, we have obtained maximum passengers and the date. (For calculating % of bonus driver)

    Please help me to write the query.

    Best regards
    Nisha

    OK, something like this:

    with my_tab as (select 1 id, 4123 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
                    select 2 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 25 passengers from dual union all
                    select 3 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
                    select 4 id, 4123 busno, to_date('06/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
                    select 5 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
                    select 6 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 19 passengers from dual union all
                    select 7 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 22 passengers from dual union all
                    select 8 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
                    select 9 id, 4123 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 23 passengers from dual union all
                    select 10 id, 4123 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 27 passengers from dual union all
                    select 11 id, 4123 busno, to_date('11/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
                    select 12 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
                    select 13 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
                    select 14 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
                    select 15 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 24 passengers from dual union all
                    select 16 id, 6138 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
                    select 17 id, 6138 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual)
    -- end of mimicking your data; use SQL below:
    select busno,
           min(start_date) start_date,
           max(start_date) end_date,
           sum(passengers) total_passengers,
           max(passengers) max_passengers,
           max_pass_date
    from   (select id,
                   start_date,
                   busno,
                   passengers,
                   distance,
                   max(start_date) keep (dense_rank first order by passengers desc) over (partition by distance, busno) max_pass_date
            from   (select id,
                           start_date,
                           busno,
                           passengers,
                           -- using tabibitosan method, borrowed from Aketi Jyuuzou
                           dense_rank() over (order by id) -
                              row_number() over (partition by busno order by id) distance
                    from   my_tab))
    group by busno, distance, max_pass_date
    order by min(id)
    
         BUSNO START_DATE END_DATE   TOTAL_PASSENGERS MAX_PASSENGERS MAX_PASS_DATE
    ---------- ---------- ---------- ---------------- -------------- -------------
          4123 04/10/2009 06/10/2009               78             25 05/10/2009
          6138 03/10/2009 04/10/2009               70             22 04/10/2009
          4123 07/10/2009 11/10/2009               65             27 08/10/2009
          6138 05/10/2009 08/10/2009              109             24 05/10/2009   
    
  • Delegate read-only for an OU select employee group

    I'm delegating read-only access to all the user accounts on a specific OU in one of our areas.

    When I add the group to the list of access with special permissions - Read all properties - it allows users to this group to change password for all accounts and group memberships in the ORGANIZATIONAL unit.

    I just want what they see information = name, address, telephone number, email, postal address and group memberships.

    What Miss me?

    any help is appreciated.

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)

    If you give us a link to the new thread we can point to some resources it
  • You can select a group of clips on the timeline to loop through reading?

    In order to help me learn reading and lessons complex clip I use Premiere Pro to isolate sections of the difficulty of the study. I have independent clips on the timeline laid out in groups, each group marked with color labels so I can review and play only the groups of clips, or "parties", overall, but I would like to isolate each of these groups a little more if I could play each independently "in the loop" so I can still study them independently and isolated from others. Is it possible to do it on the timeline? I know I can score points on the clips themselves in the preview and output screens and loop, but now I would do each set of clips on the timeline in loop in the sections of clips. I hope that I wrote this clearly.

    Put them on a different schedule and those in the playback loop.

  • Behavior on the order of the selected line group

    When you use a GROUP BY clause with one or several columns, the results will be in the sorted order of GROUP columns (default) or we will use the ORDER BY clause?

    Hello!

    Use ORDER BY, GROUP BY my using an algorithm of hash, so not necessarily rows will be sorted appropriately.

    / Jaroslaw Tajcher

  • That should make the function groups when it is selected in the phone app?

    I see an option for selecting groups when you use the Contacts feature in the phone application.  What makes that?  I want to set up groups of my own, but don't see how to do it or if it is still possible.  Any ideas?  My app has a function of groups and I set up some groups here as family, teammates in our fantasy football league, etc..

    Thank you

    jbacinti

    Basically, the use of groups allows you to send an email or a message to everyone in the group.  You simply select the group you want to instead of each individual.  To configure groups, check out these links:

    Send a message from your iPhone, iPad or iPod touch - Apple Support Group

    iCloud: create a group and add contacts

    Can create you additional groups to your Favorites. iPhone 6 s

Maybe you are looking for