Several counts and

I wrote my request and now I need to refine - I tried to comment the next step in the query. I hope it makes sense what I try to achieve, but I don't know how to write it and I had no chance to research.

Essentially, I need to see the indictment, I need to see all a.id, a.num where "Count zero" = "0" and 'Count of Zero' > '0'
select a.id, a.num,
(select Count(*)
from ari ari
where ari.id = a.id
and ari.num = a.num
and ari.value = '0') as "Count of Zero",
(select Count(*)
from ari ari
where ari.id = a.id
and ari.num = a.num
and ari.value > '0') as "Count of Non-Zero"
from ari a
--where "Count of Non-Zero" = '0' and "Count of Zero" > '0'
group by a.id, a.num 
-- having "Count of Non-Zero" = '0' and "Count of Zero" > '0'
order by a.id
Examples of data
VALUE ID NUM
32 0 0
32 0 0
32 0 0
32 0 0
32 1 0
32 1 0
32 1 0
35 0 0
35 0 23
35 0 22
35 1 0
35 1 12
35 1 24
36 0 0
36 0 0
36 0 0
36 1 26
36 1 25
36 1 45
38 0 27
12 0 38
38 0 55
38 1 42
38 1 48
38 1 40
38 1 39

The query results
a.ID a.num
32 0
32 1
36 0


Oracle 11.2.0.2.0 database

Published by: 924266 on 03/29/2012 6:14

Published by: 924266 on 06:22 29/03/2012

Edit: Thanks Frank for the fast feedback

Published by: 924266 on 03/29/2012 06:32

Hello

Welcome to the forum!

Whenever you have a querstion, don't forget to ask your question. You are looking for a better way get the same results?

SELECT       id
,       num
,       COUNT (CASE WHEN value = '0' THEN 1 END)     AS "Count of Zero"
,       COUNT (CASE WHEN value > '0' THEN 1 END)     AS "Count of Non-Zero"
FROM        ari
GROUP BY  id
,            num
ORDER BY  id
;

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Report when the above query is incorrect results and explain, using specific examples, how you get the results of these data in these places.
Always tell what version of Oracle you are using.

Published by: Frank Kulash, 29 March 2012 09:29

I see that you added your question now.

SELECT       id
,       num
FROM        ari
GROUP BY  id
,            num
HAVING    COUNT (CASE WHEN value = '0' THEN 1 END)     > 0
AND       COUNT (CASE WHEN value > '0' THEN 1 END)     = 0
ORDER BY  id
;

COUNT always returns a number, so it is not sensible to compare a string like '0'
What is the data type of the value? If it is a NUMBER. Then, you don't want to compare it to a chain, either.

Tags: Database

Similar Questions

  • I can train the UAC? I regularly run several programs and UAC asks EVERY TIME if that's OK.

    I regularly run several programs and UAC asks EVERY TIME if that's OK.

    UAC is designed to collect want programs run without my permission.  Why can't have a list of programs that are allowed to run without hindrance when I'm the one initiating this shit to begin with?
    As far as I KNOW, there are four scenarios in which UAC does not:
    • When it is off (obviously!)
    • When the actions of the programme are not potentially dangerous.
    • When a program is run under a high count.
    • When the program is running under the system account.
    Your statement "UAC is designed to catch programs who want to run without my permission" neglects the main point. UAC is designed to prevent programs from performing potentially dangerous actions such as changing the files/system folders or by editing the registry. In other words, a UAC challenge is never directed to a specific application. She always helps that tries to make a request.

    I think it would be easy for Microsoft create a list of "good guys". I also suspect that it would be just as easy for programs not allowed to populate this list without your knowledge, so beating UAC in no time at all.

  • WITH or CONNECT BY on several tables and function call

    Hi all

    I saw several post, documentation and several tutorials and cant' wrap your head around the query. I am creating a hierarchy of hosts in a model parent child and for each parent, I need to generate html code. I now have the id of the top most parent but has difficulty to get the logic to generate the output I need.

    In short, I have 1 parent with children and some of these children may be parents themselves and the parent over the top of the PAGE is always-1

    I need to call the pl/sql function to generate the code (only and only if it is a parent)

    I've been at this for awhile and only have the basics but are struggling to try to get what I need. I'im so confused at this point I don't know even how to explain it.

    So bear with me, I have included the test data for all who can help:

    -STEP 1-> OK

    -STEP 2-> DON'T know what I'm doing, but I'm generating an output of hierarchy

    -STEP 3-> paths are a bit inaccurate. DB1 and DB2 are repeated and their correct path is/LOCALHOST/RT1/SVR-DEV-01/DB1

    -STEP 4-> I'm so confused, I could not explain other then I have to call my function in reverse order of STEP2 so that more "host_object" really is a child and therefore function should not be called.

    -- Heis my query my base query
    
    SELECT DISTINCT h.id,
                    h.host_object_id,
                    h.display_name,
                    COALESCE(h3.host_object_id, -1) AS parent_id,
    
    FROM hosts h
    LEFT JOIN host_parenthosts h4 ON (h.id = h4.host_id)
    LEFT JOIN hosts h3 ON h3.host_object_id = h4.parent_host_object_id;
    

    It may be easier to do using PL/SQL. Here is an example that you may be able to take as a starting point. It uses recursion to write lines in a simple table, then writes the table at the end.

    SET SERVEROUTPUT ON
    DECLARE
    
      g_lines_list SYS.ODCIVarchar2List := SYS.ODCIVarchar2List();
      CURSOR c_top IS
      SELECT hst.id, hst.host_object_id, hst.display_name
        FROM hosts hst
       WHERE NOT EXISTS (SELECT 1
                           FROM host_parenthosts par
                          WHERE par.host_id     = hst.id
                  );
      l_id     PLS_INTEGER;
    
      FUNCTION Write_Log (p_line VARCHAR2, p_level PLS_INTEGER) RETURN PLS_INTEGER IS
      BEGIN
    
        g_lines_list.EXTEND;
        g_lines_list (g_lines_list.count) := LPad ('.', 2*(p_level+1), '.') || p_line;
        RETURN g_lines_list.count;
    
      END Write_Log;
    
      FUNCTION JSON_Expand (p_level PLS_INTEGER, p_parent_id PLS_INTEGER) RETURN VARCHAR2 IS
        l_chi_str          VARCHAR2(30);
        l_id             PLS_INTEGER;
        CURSOR c_chi IS
        SELECT hst.id, hst.host_object_id, hst.display_name
          FROM host_parenthosts          par
          JOIN hosts               hst
            ON hst.id               = par.host_id
         WHERE par.parent_host_object_id     = p_parent_id;
    
      BEGIN
    
        FOR r_chi IN c_chi LOOP
    
          IF l_chi_str IS NOT NULL THEN
            g_lines_list(g_lines_list.COUNT) := g_lines_list(g_lines_list.COUNT) || ',';
          END IF;
          l_id := Write_Log ('{Id: ' || r_chi.id || ', Name: ' || r_chi.display_name, p_level);
          g_lines_list(l_id) := g_lines_list(l_id) || JSON_Expand (p_level + 1, r_chi.host_object_id);
          l_chi_str := ', Children: [';
    
        END LOOP;
    
        IF l_chi_str IS NOT NULL THEN
    
          l_id := Write_Log (']}', p_level - 1);
    
        ELSE
    
            g_lines_list(g_lines_list.COUNT) := g_lines_list(g_lines_list.COUNT) || '}';
    
        END IF;
        RETURN l_chi_str;
    
      END JSON_Expand;
    BEGIN
    
      FOR r_top IN c_top LOOP
        l_id := Write_Log ('{Id: ' || r_top.id || ', Name: ' || r_top.display_name, -1);
        g_lines_list(l_id) := g_lines_list(l_id) || JSON_Expand (0, r_top.host_object_id);
      END LOOP;
    
      DBMS_Output.Put_Line ('Stored lines...');
      FOR i IN 1..g_lines_list.COUNT LOOP
        DBMS_Output.Put_Line (g_lines_list(i));
      END LOOP;
    
    END;
    /
    

    Strategic outcome on your data:

    Stored lines...
    {Id: 2604, Name: LOCALHOST, Children: [
    ..{Id: 2580, Name: VRT-42, Children: [
    ....{Id: 2597, Name: solaris},
    ....{Id: 2598, Name: dell-2},
    ....{Id: 2600, Name: acer-3}
    ..]},
    ..{Id: 2581, Name: RT1, Children: [
    ....{Id: 2591, Name: SVR-DEV-01, Children: [
    ......{Id: 2577, Name: DB1},
    ......{Id: 2578, Name: DB2}
    ....]}
    ..]},
    ..{Id: 2590, Name: VMHOST-01},
    ..{Id: 2591, Name: SVR-DEV-01, Children: [
    ....{Id: 2577, Name: DB1},
    ....{Id: 2578, Name: DB2}
    ..]},
    ..{Id: 2592, Name: VMHOST-02},
    ..{Id: 2594, Name: SRV-ORA-77},
    ..{Id: 2594, Name: SRV-ORA-77},
    ..{Id: 2607, Name: winserver2008}
    ]}
    
    PL/SQL procedure successfully completed.
    
  • I deauthorised all my computers several times and iTunes still shows that I have authorized 5.

    I allowed off all my computers several times and iTunes still shows that I have authorized 5. I can not re - allow one of my computers and cannot allow overall because I did last October. I tried a logout and back logging, remove the SC info folder etc... Any ideas?

    I allowed off all my computers several times and iTunes still shows that I have authorized 5

    Normally, you can only authorized computers off once a year.

  • Hangs, severe slowness and camera running Firefox 27,0 / 28.0 on Windows XP / is it possible to block plugin container?

    Experienced a severe slowness and lock-up with Firefox to the end, which ends with a sharp decline in the use of memory and I have repeatedly shut down by the Task Manager. I created a new profile and disabled hardware acceleration. I tried to disable all plug-ins and extensions, but I noticed that sometimes (not always) plugin container was always an active process, I don't understand. Why would it be active when there is no plugin activated? I also noticed that when the plugin container is not active (list under process in the Task Manager), I don't have this problem and Firefox works normally? I need to block the plugin container. Help, please.

    If you have deactivated plugins and plugin-container should not be executed. It's one of the reasons I suggested malware scans.

    The Windows XP Task Manager lists the processes running. It will list the plugin - container.exe but I don't think it goes further. IIRC a Sysinternals utility was required to get information on the processes associated with the plugincontainer.

    Microsoft will now offer free downloads and documentation for which is the Sysinternals software.

  • I worked on a large document for several years and all of a sudden I can't scroll to the bottom of the screen with my two fingers on the touchpad, well that I have no problem scrolling to the bottom of this page to search for similar issues.

    I worked on a large document for several years and all of a sudden I can't scroll to the bottom of the screen with my two fingers on the touchpad, well that I have no problem scrolling to the bottom of this page to search for similar issues. I can navigate only to go up and down with the arrow keys.

    What version of Pages is running on your MBP?

    What version of Mac OS X is running on your MBP?

    The MBP is not iOS running.

  • Firefox crashes because as his tent to update the last website I went to have uninstalled and reinstalled several times and always the case. How can I erase this site so it seems not for her? Also happens in safe mode.

    Firefox crashes because as his tent to update the last website I went to have uninstalled and reinstalled several times and always the case. How can I erase this site so it seems not for her? Also happens in safe mode.

    Follow the suggestions mentioned in the following article:

  • I have a Server R2 windows 2012 automatically switches out of his own for several times and it doesn't look like a hardware problem.

    I have a windows server R2 2012 which automatically switches out of his own for several times and it doesn't look like a hardware problem. and I have this problem every day.please tell me what is the reason

    Original title: r2 windows server 2012

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

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

    http://social.msdn.Microsoft.com/forums/en-us/home

  • My guest user account has stopped working after the installation of several windows and IE9 updates.

    I recently installed several windows and IE9 updates. During the install IE9 I stopped the installation process, because it seemed that I had two IE9 installs go. I ended up cancelling the installation so IE9 has not installed. I tried to install IE9 again and this time I can't stop installation, and it has been successful. I checked the other user profiles to make sure that everything has been installed, and that's when I noticed that my guest account wasn't just all users accounts were working well.

    Whenever I try to open a program, for example: Internet explore, any Office program and even the calculator another window opens asking me to manually locate the file I'm looking for. I am able to locate the file and open it, but as soon as I close I can't reopen unless I have to manually search for the file. There is a checkbox indicating that it automatically uses this file with the program but I can't check the box (its in a light gray that I can't click on) and I don't want to manually search the file everytime I open a program. I tried using a restore point before updates, but which did not set can guest account everyone please help?

    [1] I need to correct me by declaring that the Mcafee subscription is 18 months and its due for renewal in June, then yes its still the preinstalled version.

    [2] will certainly be your advice on that. Should what drivers I roll back?

    [3] I thought to go on this forum first, but I chose it because the error occurred while I was updating, but I'll post my question it too

    A1A. Ah! The application is named McAfee Security Center by chance?

    A1B. Do you plan to purchase a subscription for this or any other McAfee application (which you would need to do so BEFORE the expiry of 18 months 'advance')?

    A2. In re the restore drivers, you restore the drivers that you have installed via Windows Update. that is, Intel G45/G43 Express Chipset (graphics driver or screen) and Realtek PCIe GBE Family Controller (NIC driver). Again, this is a long shot.

    A3. Please do that start new thread immediately.

  • I have a PC brand new - HP and played Chess Titans. Now all of a sudden it says it cannot find the texture, but he said no zero the reference count and then could not find device 3D.

    original title: Chess Titans

    I have a PC brand new - HP and played Chess Titans.  Now all of a sudden it says it cannot find the texture, but he said no zero the reference count and then could not find device 3D.  What's past and how to fix this.  Thank you.

    These error messages can occur if you (or software) also disabled Aero. Aero must be on (and supported by the video card) to play Chess Titans. "192GO should be enough for everyone." (of the miniseries "Next generation jokes")

  • If I have several fields and if I select a field in a drop-down list it will fill the other fields

    If I have several fields and if I select a field in a drop box is it possible to auto poplulate the other fields.

    Thank you

    Brain

    Please post your question on InfoPath 2010 at the following link

    http://social.technet.Microsoft.com/forums/en-us/sharepoint2010customization/thread/e70c23a9-1b68-4EF9-9FB4-923997043e56/

  • my account has been hacked several times and sends mail spam to the people on my list

    my account has been hacked several times and is to send spam to people on my list. I changed my password several times and it continues to happen. I took everyone off my email list with the exception of an e-mail address that I created to alertme in the case of this kind of thing happens, it works. I pay for this msn messaging service and I'm upset that anyone can hack my email so easily. I want that stopped.

    It is up to you to use Kaspersky Rescue Disk 10 to remove any malware. The hot spare is a bootable Linux distribution that will search for and remove malicious software that can hide when the HD is active.
    Booting from the rescue disk will ensure the HD is not Active -Kaspersky Rescue Disk 10

    Once the system is cleaned up, contact MSN and ask another reset of password.

    Expert MowGreen Windows IT Pro - consumer safety

  • DEFENDER lights. He tells me it's off and it must be enabled. I tried several times and I can't activate it. I see the icon in my field of security. The ICON in my programs (install/remove) is NOT there? ERROR message 0x80071A90__

    I would be grateful with the help of an EXPERT.  I would be very grateful if you can help me.

    DEFENDER lights.  He tells me it's off and it must be enabled.  I tried several times and I can't activate it.  I see the DEFENDER icon (it looks like gray Castle) in my field of security.  The ICON in my programs (install/remove) is NOT there?  0x80071A90 error message
    98CB24AD-52FB-DB5F-A-15-C8B3B9AIE18E

    In ADDITION, 2nd edition: I have an infected memory stick digital camera.  It has infected my computer 4 times from AUGUST 2009 I realized that it was the culprit.  It leads to the DEATH of SCREEN BULE.  He arrived Friday.  I made the recovery of the system.  I REINSTALLED it.  QUESTIONS: What should I do with this memory stick?  Throw it in the trash?  I lost 6 months of precious photos.  Can I move photos or keep the photos?  What do you recommend?

    In ADDITION, through the memory stick infect my computer and then the PICTURES who made the infection.  About 3 or 4 flash drives have been put in my computer.  Are they all infected?  I have College CRITICISM of work on one that I can't lose.  What should I do?  Should these flash drives be CLEANED of INFECTION?  They CLEAN themselves without losing me my files stored?  What do you recommend?  I need someone to assess whether or not they are infected?

    The infected memory stick infects my digital camera?  And my Photosmart HP ALL IN ONE printer?  Are they ALSO infected?  Will be going to infect my computer.

    I do not think that the SECURITY SOFTWARE I have: (free from Comcast) Norton and Microsoft Security Essentials, are fighting the infection from the memory stick.  It would be good to have an EXPERT evaluate the memory stick and tell me what they think.  As well as my flash drives, an expert must evaluate and tell me if 3 flash drives are infected? And they are clean? And the files that I have on them can be saved?

    I hope you can help me, THANK YOU, WG

    First, you have to run two anti-virus programs.  This is NOT recommended.

    Second... you state one of them is Microsoft Security Essentials.  If this is the case, you can't turn on Windows Defender because MSE already made defender and stops automatically Defender because it is no longer necessary.

    Difficulty of these 2 things and your problem should be solved.

  • With the help of Windows to the top. -J' changed my settings on the page to backup several times, and now when I try to back up my computer it keeps default.

    TODAY, I CHANGED MY SETTINGS ON THE BACKUP OF THE PAGE WITH THE HELP OF WINDOWS BACK UP TO SEVERAL TIMES AND NOW WHEN I TRY TO BACK UP MY COMPUTER AGAIN, HE GUARD DEFAULT.
    I HAVE WINDOWS VISTA PREMIUM 64 BIT.
    I WOULD APPRECIATE YOUR RESPONSE

    Hello

    1. do you receive any error messages?
    2. what exactly happens when you try to backup data?
    3 have. what settings you changed?

    Please answer these questions. This will help us assist you better.

    Try to perform the clean boot.

    Refer; http://support.Microsoft.com/kb/929135

    Thanks and greetings
    Umesh P - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.
    [If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message.] [Marking a post as answer, or relatively useful, you help others find the answer more quickly.]

  • How can I store several sentences and insert without typing?

    How can I store several sentences and insert without typing?

    http://www.colorpilot.com/TypePilot.html

Maybe you are looking for

  • My rom version is IM121.0047.B23

    Hello I have an iMac 27 inch mid 2011 and my rom version is IM121.0047.B23. However, in all EFI and updates the SMC firmware for Mac computers with processor Intel - Apple Support, the latest version is M121.0047.21B (2015-001). What is the most rece

  • Mini Mac fails to turn off after the upgrade to El Capitan

    Hello Yesterday, I upgraded to El Capitan, unfortunately, the Mac mini does not stop and Finder is unresponsive, I am at a loss and do not know what action to take, any help would be much appreciated. Thank you rachealfromva

  • get 404 Server error when you try to play multiplayer game online Spades MSN

    I got to play MSN FREE online games of Spades until yesterday when I started getting error 404 server.  Need a fix for this problem.  Thank you.

  • Pavilion e9280t: the graphics card upgrade

    I had to spend my original GeForce GT220 graphics card to use at least three 3 monitors so I bought EVGA GeForce GT 640.  When I installed the card, everything was fine until the computer, install the driver and start then computer began to stop and

  • return the video hardware problem

    Flip software is loaded on my PC (Windows Vista Home Basic) works fine... when I go to physically plug the camera into the USB port and the error msg comes on telling me that it considers that the camera is not connected to the computer... any help?