472,378 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Multiple Counts in 1 query

I am trying to get the number of specific alerts for each month of the year. I would like to get these counts in one query or subquery. There is a date field in table so I can specifically get the counts for each individual month. Any help would be appreciated.
Jul 14 '08 #1
9 20184
debasisdas
8,127 Expert 4TB
Kindly post the query that you are working on with your underlying table structure.
Jul 14 '08 #2
I was wondering if this code would work in a sub query, not sure of the syntax.In this example, I am trying to get a count of two different types of alerts (ODC &ODW) from column Situation Name.. I want to get all the counts in one query so I can eventually do some neat graphs with the data.

Select
Count1=(Select Count (*) From TIVOLI."Status_History"
Where "Situation_Name" Like 'ODC%'),
Count2=(Select Count(*) From TIVOLI."Status_History"
Where "Situation_Name" Like 'ODW%');
Jul 15 '08 #3
amitpatel66
2,367 Expert 2GB
I was wondering if this code would work in a sub query, not sure of the syntax.In this example, I am trying to get a count of two different types of alerts (ODC &ODW) from column Situation Name.. I want to get all the counts in one query so I can eventually do some neat graphs with the data.

Select
Count1=(Select Count (*) From TIVOLI."Status_History"
Where "Situation_Name" Like 'ODC%'),
Count2=(Select Count(*) From TIVOLI."Status_History"
Where "Situation_Name" Like 'ODW%');

Try This:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT SUM(CASE WHEN situation_name LIKE 'ODW%' THEN 1 ELSE 0 END) cnt_odw, SUM(CASE WHEN situation_name LIKE 'ODC%' THEN 1 ELSE 0 END) cnt_odc FROM TIVOLI."Status_History
  3.  
  4.  
Jul 15 '08 #4
Tried it and got syntax errors. Sorry could not get screen print
Aug 1 '08 #5
amitpatel66
2,367 Expert 2GB
Tried it and got syntax errors. Sorry could not get screen print

What is the error that it is displaying?
And let me know the oracle version that you are using?
Aug 1 '08 #6
I corrected the syntax errors. "System_History" needed double quotes at the end and "Situation_Name" need the first letter to be in caps. I need to add a few more things but you got me in the right direction. Thank yo so much !!
Aug 10 '08 #7
Try This:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT SUM(CASE WHEN situation_name LIKE 'ODW%' THEN 1 ELSE 0 END) cnt_odw, SUM(CASE WHEN situation_name LIKE 'ODC%' THEN 1 ELSE 0 END) cnt_odc FROM TIVOLI."Status_History
  3.  
  4.  
How would I get these counts for a certain time period. (monthly weekly etc). I want to have a bar graph that shows me all the ODC/ODW alerts for the month of JAN, FEB etc I know I need to add WHERE statement for the different time periods but how to code it and get the count for each month is my problem.
Aug 10 '08 #8
Try This:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT SUM(CASE WHEN situation_name LIKE 'ODW%' THEN 1 ELSE 0 END) cnt_odw, SUM(CASE WHEN situation_name LIKE 'ODC%' THEN 1 ELSE 0 END) cnt_odc FROM TIVOLI."Status_History
  3.  
  4.  
Wondering why SUM was used instead of count. just learning SQL
Aug 10 '08 #9
How would I get these counts for a certain time period. (monthly weekly etc). I want to have a bar graph that shows me all the ODC/ODW alerts for the month of JAN, FEB etc I know I need to add WHERE statement for the different time periods but how to code it and get the count for each month is my problem.
See my code below, received Oracle SQL 933 error

SELECT SUM(CASE WHEN "Situation_Name" LIKE 'ODW%' THEN 1 ELSE 0 END) cnt_jan
From TIVOLI."Status_History"
Where "OD_Timestamp" Between
TO_TIMESTAMP ('31-Dec-2007 00:00:01.000000', 'DD-Mon-YYYY HH24:MI:SS.FF') and
TO_TIMESTAMP ('01-Feb-2008 23:59:59.999999', 'DD-Mon-YYYY HH24:MI:SS.FF'),
SELECT SUM(CASE WHEN "Situation_Name" LIKE 'ODW%' THEN 1 ELSE 0 END) cnt_feb
From TIVOLI."Status_History"
Where "OD_Timestamp" Between
TO_TIMESTAMP ('31-Jan-2008 00:00:01.000000', 'DD-Mon-YYYY HH24:MI:SS.FF') and
TO_TIMESTAMP ('01-Mar-2008 23:59:59.999999', 'DD-Mon-YYYY HH24:MI:SS.FF');
Aug 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jim | last post by:
I'm having trouble doing multiple counts with groups, ordering, and joins. Can someone help me out? Below is two table samples and what I'm trying to get my output to be: TABLEA ID ...
2
by: Scott Cannon | last post by:
I am trying to query 3 tables all related by Clinet_ID. The Clients table, Monthly_Expenses table and Monthly_Income table. Each client can have 0>M instances of expenses, past due expenses, and...
1
by: Jeff Homan | last post by:
Hello all, I have a problem with a query in Access 97, and I'll try to give you all of the details to see if you have any idea if it's even possible: I have 2 tables: Inventory and Pricing ...
8
by: Tetelestai | last post by:
I would like three counts in one query based on differing criteria. Each count is counting the same items. The difference between the items being counted is the characteristics (eg like to short). ...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
2
by: Leventcos21 | last post by:
Hi all, I have been stuck on this issue for weeks now and can not find a solution, so I hoping that someone can help me out. I am setting up a training database. I have setup the structure and...
4
by: pafke | last post by:
Imagine you have a table with the following fields: Customer-id nvarchar(50) status int Records : Customer id status X 1 X 2
3
by: Wildster | last post by:
Hi, How can you count x and y as seperate counts from the same field? i.e. A table has the field Gender and I want to have one count which counts the number of records with 'male' as the...
3
by: rhonda6373 | last post by:
Is it possible to have counts from two different tables in one query? I tried this and it worked, but I have duplicate rows with the same count numbers.
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.