SELECT and COUNT() combinations

I have an array of PROJECTS and the two fields A and B values. Common has; "xxxxxxx0101", "xxxxxxx0102", "xxxxxxx0103". There are almost always 37 different combinations, where the 8th and 9th character is '0' and '1' - but not always. How can I count the number of combinations in my query?

I use suite SQL, but it takes the number of combinations to be 37.
SELECT
     SUBSTR(A, 8, 2),
     SUBSTR(A, 10, 2),
     37
FROM
     PROJECTS
WHERE
     B = '3213213'
GROUP BY
     A
ORDER BY
     A ASC
Published by: 964656 on 2012-10-11 00:46

Try this

not tested

select a,count(*) over(partition by substr(a,1,9))
from table_name

Tags: Database

Similar Questions

  • Select and count

    Hi friends...

    I have 2 tables A and B


    Table A
    ----------------------------------
    ID | NAME
    -----------------------------------
    1. M

    2. N

    3. O

    4. P



    Table B
    ----------------------------------------------------------------------------------------------------
    COVER | NAME | PARENT
    -----------------------------------------------------------------------------------------------------
    10. N | M

    11. N | O

    12. P | N

    13. O | M


    My requirement is to count the number of entries for which Parent is M directly or indirectly

    So, the result should be as

    PARENT COUNTY
    3 M
    O 2
    P 0

    I tried to use connect by but I can't do it.

    Can you please help me with it?

    Thank you

    Hello

    user10819722 wrote:
    ... So, the result should be as

    PARENT COUNTY
    3 M
    O 2
    P 0

    Shoudn't the results also include this line?

    parent     count
    ------     -----
    N     1
    

    I tried to use connect by but I can't do it.

    CONNECT is the right tool for the job. Here's a way to do it:

    WITH     got_ancestors     AS
    (
         SELECT       CONNECT_BY_ROOT parent     AS ancestor
         ,       name                    AS descnedant
         FROM       b
         CONNECT BY     parent     = PRIOR name
    )
    SELECT       a.name
    ,       COUNT (DISTINCT g.descendant)     AS total_descendants
    FROM           a
    LEFT OUTER JOIN  got_ancestors  g  ON  a.name  = g.ancestor
    GROUP BY  a.name
    ORDER BY  a.name
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.

    This assumes that tale contains a one line per name. There may be names that never appear in table b at all; they will have 0 counties, of course.

  • Select, grouping and counting...

    Hi again once, I managed to work around my problem of trigger, then thank you very much...!
    Now, I have a simple question...

    With the help of two tables, player (areas (PK), (PK, FK1), Noah NomJ, address, Tel., GoC)
    and team (NomE, NoJC (PK, FK1), Noah (Fk1 areas))


    I'll explain the model...

    This is a table of the team and a player Table.
    Naturally, the PK on Player (player) is Noah (team number) and areas (number of players)

    The team table, the primary key is Noah (team number
    and the foreign key is NoJC Noah, representing the number of player CAPTAIN...

    Then...
    I have to make a table of 4 plate: number (Noah), (NomE) team name, team captain name, number of players in the team...
    So I need to combine these two tables... on the first Panel, I had all the info BUT the number of players, which lists all the 1 because of the place where NoJC = areas... but this is necessary to get the name of captain...

    Select NoE, NomE, NomJ as Capitaine, count(*)
    from EQUIPE join JOUEUR using (NoE)
    where NoJ=NoJC
    group by NoE, NomE, NomJ;
    
    select noe, count(*)
    from EQUIPE join JOUEUR using (NoE)
    group by noe;
    Any clue?

    Solkution with ansi syntax

    with  equipe as ( select  1 noe ,'RC Kouba 'NomE, 1 NoJC from dual ),
    joueur  as ( select 1 NoJ, 1 NoE, ' Salim'NomJ , '.....  Montre al'Adresse,
      ' 514 111-1111'Tel,' n' CoJ from dual
        union all
                        select 2 NoJ, 1 NoE, ' Fabien'NomJ , '.....  Montre al'Adresse,
     ' 514 111-2222'Tel,' n' CoJ from dual
       union all
                       select 3 NoJ, 1 NoE, ' Ricahrd'NomJ , '.....  Montre al'Adresse,
     ' 514 111-3333'Tel,' n' CoJ from dual )
    select  noE, equipe.nomE, equipe.noJC as Capitaine,j.nomj ,count (noJ) as "Nombre de joueurs"
    from equipe join joueur  using (noE)
    join   joueur j
    on(noJC=j.noj )
    group by Noe,nome, equipe.noJC,j.nomj
    
    SQL> with  equipe as ( select  1 noe ,'RC Kouba 'NomE, 1 NoJC from dual ),
      2  joueur  as ( select 1 NoJ, 1 NoE, ' Salim'NomJ , '.....  Montre al'Adresse,
      3    ' 514 111-1111'Tel,' n' CoJ from dual
      4      union all
      5                      select 2 NoJ, 1 NoE, ' Fabien'NomJ , '.....  Montre al'Adresse,
      6   ' 514 111-2222'Tel,' n' CoJ from dual
      7     union all
      8                     select 3 NoJ, 1 NoE, ' Ricahrd'NomJ , '.....  Montre al'Adresse,
      9   ' 514 111-3333'Tel,' n' CoJ from dual )
     10  select  noE, equipe.nomE, equipe.noJC as Capitaine,j.nomj ,count (noJ) as "Nombre de joueurs"
     11  from equipe join joueur  using (noE)
     12  join   joueur j
     13  on(noJC=j.noj )
     14  group by Noe,nome, equipe.noJC,j.nomj
     15  /
    
           NOE NOME       CAPITAINE NOMJ     Nombre de joueurs
    ---------- --------- ---------- -------- -----------------
             1 RC Kouba           1  Salim                   3
    
    SQL> 
    
  • selection of special days and counting

    Hi all
    I need to select certain dates and the following days with the same criteria.
    An example would be:

    CREATE TABLE DEMO
    (
    EMP_ID NUMBER NOT NULL,
    WORKING_DAY DATE NOT NULL,
    ACTIVE_CODE NULL VARCHAR2 (1).
    CONSTRAINT DEMO_PK
    KEY ELEMENTARY SCHOOL (EMP_ID, WORKING_DAY)
    USING INDEX
    )


    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('01.11.2010 00:00:00 '), '_');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('02.11.2010 00:00:00 '), '_');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('03.11.2010 00:00:00 '), 'K');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('04.11.2010 00:00:00 '), 'K');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('05.11.2010 00:00:00 '), 'K');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('06.11.2010 00:00:00 '), NULL);
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('07.11.2010 00:00:00 '), NULL);
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('08.11.2010 00:00:00 '), 'K');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('09.11.2010 00:00:00 '), '_');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('10.11.2010 00:00:00 '), 'K');
    INSERT INTO DEMO (EMP_ID, WORKING_DAY, ACTIVE_CODE) VALUES (123, TO_DATE ('11.11.2010 00:00:00 '), '_');

    Now, I'm looking for the first day with Active_Code = 'K' and count the days that have 'K', too.
    Expected result: November 3-> 4 Ks (because the 8 is after the weekend); 10 November-> 1 K

    I hope that the example/explanation is not too bad...

    I built a procedure which was to count the occurrences, if I give the first occurrence (here the 3rd and 8th).
    But findign the first 'K' is my problem.
    A solution would be:
    AND
    (SELECT T2. T2 DEMO ACTIVE_CODE
    WHERE T2. EMP_ID = T1. EMP_ID AND T2. WORKING_DAY = T1. WORKING_DAY-1) <>'K '.
    AND
    (SELECT T2. T2 DEMO ACTIVE_CODE
    WHERE T2. EMP_ID = T1. EMP_ID AND T2. WORKING_DAY = T1. WORKING_DAY-2) <>'K '.
    AND
    (SELECT T2. T2 DEMO ACTIVE_CODE
    WHERE T2. EMP_ID = T1. EMP_ID AND T2. WORKING_DAY = T1. WORKING_DAY-3) <>'K '.

    But it is pretty darn imperformant if I'm dealing with millions of records :-(

    Could someone please give me a hint on how to solve this problem?
    Thank you.

    Best regards
    Christian

    Hi, Christian,.

    Assumiung you have exactly one line for each working_day (where active_code is not NULL):

    WITH     got_grp_num     AS
    (
         SELECT     emp_id
         ,     working_day
         ,     active_code
         ,       ROW_NUMBER ()
                      OVER ( PARTITION BY  emp_id
                          ORDER BY          working_day
                        )
               - COUNT ( CASE
                       WHEN  active_code = 'K'
                       THEN  1
                   END
                    )     OVER ( PARTITION BY  emp_id
                          ORDER BY          working_day
                        )      AS grp_num
         FROM     demo
         WHERE     active_code     IS NOT NULL
    --     AND     ...     -- Any filtering goes here
    )
    SELECT       emp_id
    ,       MIN (working_day)     AS first_day
    ,       COUNT (*)          AS cnt
    FROM       got_grp_num
    WHERE       active_code     = 'K'
    GROUP BY  emp_id
    ,       grp_num
    ORDER BY  emp_id
    ,         first_day
    ;
    

    I'm guessing on the emp_id role in this problem.

    The trickiest part of this problem is to obtain an appropriate value for the GROUP BY.
    When you have several consecutive lines of 'K', the difference between the ROW_NUMBER (in cash lines no 'K', but not weekends) and the number of lines of 'K' previous will be constant. This is what grp_num is. (A non - adjacent lines 'K' also has the same grp_num, but that's OK, it will be rejected by the WHERE clause in the main query.)

    Published by: Frank Kulash, November 4, 2010 05:43

  • Max, Min, and Count with Group By

    Hello

    I want the max, min and the meter of a table that is grouped by a column

    I need a combination of these two selects:

    select
         max(COUNTRY_S) MAXVALUE,
         min(COUNTRY_S) MINVALUE
    from
         tab_Country
    
    

    select
         count(*)
    from
         (select COUNTRY_TXT from tab_Country group by COUNTRY_TXT) ;
    
    

    The result should be a line with the maximum and minimum of the table value and the County grouped by table, not the max and min of each group! -J' hope you understand my question?

    Is this possible in a SQL-select?

    Thank you very much

    Best regards

    Heidi

    Hi, Heidi,.

    HeidiWeber wrote:

    Hello

    I want the max, min and the meter of a table that is grouped by a column

    I need a combination of these two selects:

    1. Select
    2. MAXVALUE, Max (COUNTRY_S),
    3. min (COUNTRY_S) MINVALUE
    4. Of
    5. tab_Country
    1. Select
    2. Count (*)
    3. Of
    4. (select the COUNTRY_TXT of the COUNTRY_TXT tab_Country group);

    The result should be a line with the maximum and minimum of the table value and the County grouped by table, not the max and min of each group! -J' hope you understand my question?

    Is this possible in a SQL-select?

    Thank you very much

    Best regards

    Heidi

    It is not clear what you want.  Maybe

    SELECT MAX (country_s) AS max_country_s

    MIN (country_s) AS min_country_s

    COUNT (DISTINCT country_txt) AS count_country_txt

    OF tab_country

    ;

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • How can I copy 2 pages and turn them into a new pdf document? I can highlight pages, export and then combine files into new pdf, but it's very heavy. Acrobat DC, I cannot open 2 files acrobat side by side.

    I have a 600-page adobe document. How can I copy 2 pages and turn them into a new document? I can highlight pages, export and then combine files into new pdf, but it's very heavy. Acrobat DC, I cannot open 2 files acrobat side by side. In the past, I could take two pages and copy and insert into the document opened adjacent... Thank you

    I'm not what you mean... Start by describing what tools or methods that you use to extract these pages.

    What you write in the first sentence is not true, however. In the dialogue window extract Pages, you can choose whether or not to delete the extracted pages of the original file and extract them as individual pages or not. If you UN-select both options, you will get a single file that contains the pages you have checked out, and they will not be deleted from the original file.

  • Worn and counting on the same query?

    I have a table with the following fields: groupname, FULL_NAME, DEFAULT_X, SUPPORT_GROUP_ID and PERSON_ID (among others)
    A user (PERSON_ID) can be different times, they appear once for each group (SUPPORT_GROUP_ID) that they are assigned to.
    When the DEFAULT_X == 0, this means that the user's default group is on this line. Each user should have only one only by default the group, but for some reason, the table was corrupted and there are a few users that don't have a default group.
    What I'm trying to do is to select all the users (FULL_NAME, PERSON_ID) where the PERSON_ID COUNTY is equal to the SUM of DEFAULT_X
    It sounds easy enough, but I don't even know where to start.
    Any suggestions?

    Hello

    So you say
    default_x = 0 if this is the default group, and
    default_x = 1 in all other cases
    Is this fair?

    If so, you can say:

    SELECT    person_id
    FROM      table_x
    GROUP BY  person_id
    HAVING    COUNT (*) = SUM (default_x);
    

    HAVING is similar to WHERE, except that HAVING is applied after the merger took place and functions of aggregation (like SUM and COUNT) were calculated.

    However, your problem is that default_x is not entered correctly. If default_x is sometimes 1 to 0, are not concerned it may contain other errors, like having 2 or - 1, whereas she would have to have 1?

    Here's a better way to find person_id who don't exactly have a single line with default_x = 0:

    SELECT    person_id
    FROM      table_x
    GROUP BY  person_id
    HAVING    SUM
              (
                  CASE
                      WHEN  default_x = 0
                      THEN  1
                      ELSE  0
                  END
              ) != 1;
    
  • Going crazy trying to select and move multiple points of tempo

    I tried to move a whole bunch of tempo of a bar points to a spot 4 bars later in my project. First time this... For the life of me I can't figure out what I'm doing wrong as I * try * follow the steps here: Logic Pro X: move and copy points of tempo

    Here's a quick screencast to choose me (while holding the CONTROL key) and then drag (hold down CTRL key):

    https://youtu.be/HpLHQbV4y9U

    (The editor let me not insert a video this time so I downloaded on YouTube instead.)

    I tried dragging dragging the first point of tempo, dragging from the last point of tempo, a place randomly in the Middle the selected points. I also tried now the shift and CONTROL simultaneously select and drag when he did not work on the other hand, only because the instructions mentioned the option to SHIFT + click in the selection. Finally, I tried the same thing while now the SHIFT key instead of CONTROL (don't wait not that it works of course because the instructions didn't say to do, but I tried the way described several times and she didn't).

    Get these points of tempo settles is the last detail in a huge song that ended the case

    There must be some small detail that I forgot the instructions. Any suggestions? Thanks in advance!

    Use the smudge tool to enter the automation of tempo and move it left or right...

  • In writing e-mail, addresses are not sorted for easy selection and often appear in red when found (V31.3).

    A small 'feature '...
    Using Thunderbird 31.3.0 on WIndows 7 and Windows 8 (2 different machines).
    In the "Write" e-mail window when you try to select addresses from the address book, the address list is not sorted. Type the first letter of the address, the unsorted list is presented, on the typing of the second letter, 2 letters are disaplayed in red. If you scroll the list to find the desired address, it can be selected and the email is sent ok (it shows just the address in red).
    Thank you.

    Keep typing. Search now uses 'contains' while in the past he has used "begins by".

    Red is a bug and no real consequence as long as you are careful to accept such address offered.

    More concern with the current version is that it would have been is not always check the address you have chosen. I don't know what triggers what I was not able to replicate.

  • How to select and move more than one bookmark at a time? Shift + click selects multiple items that are next to each other in a list, because the element

    How to select and move more than one bookmark at a time?
    Shift + click selects multiple items that are next to each other in a list, because the items open in firefox before that happens.

    Glad it worked for you. Thanks for posting back.

  • On Mac Book Pro, how can I select and delete spam with it opening?

    On Mac Book Pro, how can I select and delete spam with on their opening?

    Go to the junk mail folder in the Mail sidebar. Place the cursor in the message window and press command + A to select all of the messages in the window. Click on the trash in the toolbar or CTRL - RIGHT click and select the Recycle Bin on the shortcut menu.

  • Equium M50 bypasses sometimes screen selection and password of account completely

    Sometimes when I start my Equium M50, it goes to the screen selection and password of the user account. Other times he who circumvents completely and go directly to the desktop.

    Hello

    Did you mean the user Windows XP normally account?
    Have you set the password to your account?

    I put t know if it helps but I recommend to delete your old user account and create a new password.

    Windows XP administrator account (versions Home and Professional).
    By default, it doesn't have a defined password.
    In order to avoid serious security problems, it is best to set a password for this account on your computer.
    To do this, follow these instructions:

    1. open the start menu, and then click Control Panel.
    2. in Control Panel, open the icon user accounts.
    3. the screen user accounts lists several accounts that are present on your machine. Note that you will have probably a Director and another (that you named when you configure your computer to start). Select the administrator account.
    4. in the administrator account settings screen, click the "Create a password" link.
    5. in the password creation window, fill in the blanks required. When finished, press to create the password.
    6 you may be asked if you want to make this private account files. Click on either YES or NO (depending on your preferences), then click on finish
    7. it must be returned to the window user accounts. Close this window, and then restart your computer normally.

    NOTE: Make sure you add passwords on ALL accounts on your computer

  • Amnesty International and counter sync + USB signal stream (USB-6210 vs USB-6341)

    Hi all

    I'm at a stage of identification of a material suitable for the following tasks:

    • 5 analog inputs (AIs) of reading at the same time, tensions at a rate of kSps (at least) 10,
    • application captures 2 inputs using timers (detection of contours with timestamps), square wave entry with duty ratio of 50 percent and about 1.5 kHz frequency and variable pulse width / frequency (from 2 sensors hall, representative of the DC motor rotation speed and direction, quadrature signals), resolution of timestamps should be (at least) 50 ns,
    • AIs and counters should behave in a deterministic way, and must be synchronized in a way,
    • data to be transferred via the USB port of a host computer with Matlab Data Acquisition Toolbox (unfortunately not LabVIEW).

    I've identified the long USB-6210 USB-6341 and potential candidates of material to accomplish the above tasks, but after reviewing several documentation and the topics of the forum, I'm still a bit confused, if both are fully working and my approach described below is not working properly.

    Counters: I intend to use the internal time base available 20 MHz as being the source of meter to get into account the resolution of timestamp 50 ns. External impulses hall are used as sample clock (about 1.5 kHz, see above). As the pulse width varies, the sample clock is not constant.

    AIs: Using a 10 kHz internal clock signal derived from the time base of 20 MHz for timing and analog inputs (trigger) start-up and counters simultaneously material should translate into the required synchronization and deterministic behavior.

    It work? Other recommendations?

    Next is the USB data transfer: all HAVE 5 and 2 data entry of the meter must be correctly transferred to the host computer (the corresponding rates are shown above). USB-6210 is capable of 4 USB signal flow, device USB X range (6341) offers 8 of them. Unfortunately, I could not understand the exact meaning of the expression "signal flow" still. Do I need 1 flow of input signals (would be 7 for my application described) or 1 stream for all analog inputs and 1 for counter inputs (lead 2 streams for my request). Is there no further details on this approach (more than Streaming of signals of NOR) USB signal flow?

    Any challenge to the described application that I might have forgotten? 6210 USB seems to a very limited number of entry PFI, maybe even too low for my meter participate application?

    Looking forward to your comments and advice.

    Concerning

    jAwA

    1. I recommend the X-6341 series on the M-series 6210 sake of counters/timers.  It is more of them, and each of them is more capable.   It can also have a great FIFO embarked for meters that may be important in certain tasks, although I don't think that you currently deal with one of them.

    2. your general concepts on timing & sync are satisfactory.  You will be able to share and to route signals that help ensure synchronization and determinism between the timestamps for your various tasks.  Note that for meter entry tasks, you need set up the trigger 'Arm Start' rather than the regular start trigger.

    3 is not authoritarian, but I believe that the flow of signal # will correspond to the tasks #.  For you, it would be 1 task of HAVE and tasks CI 1 or 2.  (Not clear if you have 1 Encoder with 2-channel quad that would require 1 task of CI, or if you have 2 encoders with 4-way quad).

    4. pay attention to the hall effect signals that are not virgins.  Digital filtering is available and probably better on the X-series, the series M.

    5. strictly speaking, edge detection is a type of digital input task that produces samples but no timestamps.  Ideally, I would like to parallel wires on the two digital inputs for the entries of detection and counter change to position quadrature decoding.   Then I would sample the counters Encoder 1 or 2 using the internal pulse 'event of detection of change '.  I would create another counter timestamp change detects pulses as well.

    -Kevin P

  • HP envy 15j012la: win 10 update stay at 55% for 5 hours and counting

    Please help me im sure something's wrong, "windows setup all the update 10 55% disable" its been 5 hours and count on this screen.

    Hi @Zarped ,

    Thank you for visiting the HP Forums! A place where you can find solutions for your problems, with the help of the community!

    I stumbled upon your post on the laptop and wanted to help you! I looked in your question on your HP ENVY 15-j012la Notebook and problems with it does not not with a Windows 10 update. Try perform a reset.

    When you perform a hard reset note remove all USB devices. Disconnect all non-essential devices.

    It should continue where it left off.

    Please let me know how it goes.

    Thank you.

  • How to incorporate the timestamp and file name automatically select and save the file dialog?

    Hello

    I try to incorporate the name of the file that is the registration of the end user with the timestamp in the selected and save file dialog box. Can you help me?

    Thank you

    Hi Mike227,

    I couldn't find a way to immediately make the bat. I guess you need to mess with ActiveX to do. I found an msdn page that could help with this.

    Have you considered simply concatenating the name of the file and the time stamp with a path of the file and save the file when you create it, without inviting the user?

Maybe you are looking for

  • NSmail

    There was a problem, including the file:///C:/DOCUME~1/Layton/LOCALS~1/Temp/nsemail.html file in the message. You want to continue to send the message without this file? This is the message I get when I try to send an email

  • Satellite A200-1AX: slow HDD during music playback?

    Hey all,. I have had this problem since I have this laptop.Whenever I start my laptop, when I play a song, the computer hangs for about 10 seconds and the HARD drive seems to work without interruption, but when I suspend or stop the song, it goes bac

  • Fax and scanning of accidents

    Very happy that the scanning with my LaserJet 1220 is supported under Windows7 with scan drivers and Microsoft Scan and Fax. [Previously it has been supported under XP but not Vista]. I have run the Microsoft Scan application and Fax, and it tells wi

  • OfficeJet software 4620 slows down the PC

    After you install the software for the HP Officejet 4620 on my laptop HP with Windows 7, the mouse pointer has the image of a circle Turning next to him, and the mouse pointer is delayed during travel/selection.  The image is displayed for 5 seconds

  • View Z10 screen on PC?

    I would like to be able to demonstrate an application Z10 on a PC and not directly on a projector. Is this possible?