SQL query to count number of VMs

In OVM 2.2 I could run a SQL query against the OVM database to count the number of VMs that I had created, for automated reporting purposes.
I've looked at the 3.1 OVM database and it looks like most of the data is kept in BLOB columns. So does anyone know how I might query the 3.1 database to count the number of VMs?
Thanks.

Hi,
Combine the relevant data from the three tables (using UNION ALL) in a sub-query. without the GROUP BY.
Your main query can select from the sub-query's result set, as if it were a table. Do the GROUP BY in the main query.
That is:
WITH     u     AS
     SELECT     TO_CHAR (emp_start, 'YYYY') AS yr     FROM     Adminstaff
    UNION ALL
     SELECT     TO_CHAR (emp_start, 'YYYY') AS yr     FROM     Clerk
    UNION ALL
     SELECT     TO_CHAR (emp_start, 'YYYY') AS yr     FROM     ITstaff
SELECT     COUNT (*)      AS cnt
,     yr
FROM     u
GROUP BY     yr
ORDER BY     cnt     DESC
;Since empno is the primary key, it's easier not to mention empno at all in the sub-query, and use "COUNT (*)" instead of "COUNT (empno)" in the main query. The results are the same.
It might be a little more efficient to GROUP BY in all three branches of the sub-query, and then to SUM the results in another GROUP BY in the main query. That means more code, of course, which I'll leave as an exercise for you.
Why do you have three separate tables? I can understand that nobody else wants to be near the IT Staff, but it seems like lots of things (including this job) would be a lot simpler if all employees were all in one table, with a column to designate to which group (Adminstaff, Clerk or ITStaff) each one belongs.

Similar Messages

  • How to write sql query for counting pairs from below table??

    Below is my SQL table structure.
    user_id | Name | join_side | left_leg | right_leg | Parent_id
    100001 Tinku Left 100002 100003 0
    100002 Harish Left 100004 100005 100001
    100003 Gorav Right 100006 100007 100001
    100004 Prince Left 100008 NULL 100002
    100005 Ajay Right NULL NULL 100002
    100006 Simran Left NULL NULL 100003
    100007 Raman Right NULL NULL 100003
    100008 Vijay Left NULL NULL 100004
    It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
    I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains  both left_leg and right_leg id, then it is called pair.)
    I know there are three pairs under id "100001" :-
    1.  100002 and 100003
    2.  100004 and 100005
    3.  100006 and 100007
        100008 will not be counted as pair because it does not have right leg..
     But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
    Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005

    Sounds like this to me
    DECLARE @ID int
    SET @ID = 100001--your passed value
    SELECT left_leg,right_leg
    FROM table
    WHERE (user_id = @ID
    OR parent_id = @ID)
    AND left_leg IS NOT NULL
    AND right_leg IS NOT NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Sql query to get number of days monthwise

    Hi,
    i am new to sql, can anyone please tell me query to find number of working days between two dates month wise.
    say
    firstdate last date
    21/03/2011 25/06/2011
    march april may june
    9 22 23 18

    Hi,
    918373 wrote:
    even a result like,
    stud_id month amount
    1234 MAR-11 xyz
    1234 JUL-11 ...Please post the exact output that you want.
    Do you want 'xyz' in the output, or do you want a number like 42 (2 hours * 6 weekdays in March 2011, plus 5 hpours * 6 weekdays = 12 + 30 = 42)?
    If you want 42, then post 42. Spend 5 minutes (if it comes to that much) with a calendar and a calculator to get the exact results you want.
    >
    >
    is much better,
    in that case i want it as a view, so that i can get further details from the view....Substituting your table and column names, into the query I posted earlier and replacing COUNT (*) with SUM (no_of_hours), the query is
    WITH     cntr     AS
         SELECT     LEVEL - 1     AS n
         FROM     (
                  SELECT  MAX (enddate - startdate)     AS days_in_range
                  FROM    class_dets
         CONNECT BY     LEVEL     <= 1 + days_in_range
    SELECT       x.stud_id
    ,       TO_CHAR ( TRUNC (x.startdate + c.n, 'MONTH')
                , 'fmMonth YYYY'
                )               AS month
    ,       SUM (no_of_hours)          AS total_hours
    FROM       class_dets  x
    JOIN       cntr        c  ON   x.enddate >= x.startdate + c.n
    WHERE       TO_CHAR ( x.startdate + c.n
                  , 'DY'
                , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
                )      NOT IN ('SAT', 'SUN')
    GROUP BY  x.stud_id
    ,            TRUNC (x.startdate + c.n, 'MONTH')
    ORDER BY  x.stud_id
    ,            TRUNC (x.startdate + c.n, 'MONTH')
    ;The output, with the sample data you posted, is:
    `  STUD_ID MONTH                                     TOTAL_HOURS
          1234 March 2011                                         42
          1234 April 2011                                        147
          1234 May 2011                                          154
          1234 June 2011                                         154
          1234 July 2011                                          72
          1234 August 2011                                        46
          1234 September 2011                                     14
          1235 June 2011                                          36
          1235 July 2011                                          84
          1235 August 2011                                        92
          1235 September 2011                                     88
          1235 October 2011                                       12
          1236 June 2012                                          56
          1236 July 2012                                         154
          1236 August 2012                                        14Aside from pivoting, is that what you want?
    i edited the your query,
    WITH     all_dates     AS
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=1236), 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ((select enddate from class_dets where stud_id=1236), 'DD/MM/YYYY')     AS end_dateInstead of the 2 lines above, the query I posted had
    SELECT  MAX (enddate - startdate)     AS days_in_rangeWhy did you make that change?
    The first argument to TO_DATE is supposed to be a string. You're calling TO_DATE with this as the first argument
    (select startdate from class_dets where stud_id=1236)which is a DATE, not a string.
                   FROM     dual
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    SELECT     TO_CHAR ( TRUNC (a_date, 'MONTH')
              , 'fmMonth YYYY'
              )               AS month
    ,     COUNT (*) * (select fee from class_dets where stud_id=1236) * (select no_of_hours from class_dets where stud_id=1236)               AS amount
    FROM     all_dates
    WHERE     a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY TRUNC (a_date, 'MONTH')
    ORDER BY TRUNC (a_date, 'MONTH')
    it works very well, but instead of specifying stud_id as 1236,
    but when i say,
    WITH     all_dates     AS
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=cd.stu_id), 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ((select enddate from class_dets where stud_id=cd.stud_id), 'DD/MM/YYYY')     AS end_date
                   FROM     dual
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    SELECT     cd.stud_id,TO_CHAR ( TRUNC (a_date, 'MONTH')
              , 'fmMonth YYYY'
              )               AS month
    , count(*)
    ,     COUNT (*) * (select fee from class_dets where stud_id=1236) * (select no_of_hours from class_dets where stud_id=1236)               AS amount
    FROM     all_dates,class_dets cd
    WHERE     a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY TRUNC (a_date, 'MONTH'),cd.stud_id
    ORDER BY TRUNC (a_date, 'MONTH'),cd.stud_id
    i get error
                   SELECT     TO_DATE ((select startdate from class_dets where stud_id=cd.stu_id), 'DD/MM/YYYY')     AS start_date
    ERROR at line 6:
    ORA-00904: "CD"."STU_ID": invalid identifierThere's no column called stu_id in class_dets. There is a column called stud_id (with 2 'd's).
    >
    what should i do?
    (sorry about the query format...how display query in a formatted way? )This site noramlly compresses whitespace.
    Whenever you post formatted text (including, but not limited to, code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sql query to count

    Hi guys,
    I need to count number of values in one column which I need to query it and display the count and values as two.
    column_name data
    moderator yes,no
    so here in the moderator column there is two values with ',' separator. now I need to take count as two values.
    Please suggest me how to query this as count is 2. Can any one help on this.
    Thanks in advance!
    Regards,
    LK

    WITH T AS (
    SELECT 'yes,no' MCOL FROM DUAL
    UNION
    SELECT 'yes' MCOL FROM DUAL
    UNION
    SELECT 'no' MCOL FROM DUAL
    SELECT SUM(CASE WHEN INSTR(MCOL,',') > 0 THEN 2 ELSE 1 END) TOTAL FROM t;If you'll have more than 1 comma in your values, there can be written a function to count commas etc...
    Best Regards,
    Gokhan
    If this question is answered, please mark appropriate posts as correct/helpful and the thread as closed. Thanks

  • QUERY WHICH COUNTS NUMBER OF TIMES WORDS/LETTER APPEAR IN SENTENCE - Thanks

    I have this query below
    it gives the number of times a txn is hign comfort and Approved
    .. nyumber of times txn is meduim comfort and approved etc.
    There is a futher line whihc shows the number of times txn is blacklisted BL COUNT.
    I am trying to get line of query which can show me the number of times txn is approved, is high comfort and blcklisted ( the same applies for
    wl - watch listed)
    The query i am using
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('BL(%') and cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
     THEN 1
    ELSE 0 END)AS hbcl  - NO RESULTS BEING GIVEN
    pLEASE CAN ANYONE HELP,. THANKS
    QUERY
    USE RiskManagementReporting
    GO
    DECLARE
    @StartDate DATETIME,
    @EndDate DATETIME
    SET @StartDate
    = '2014-01-01 00:00:00'
    SET @EndDate
    = '2014-03-31 23:59:59'
    SELECT
    CONVERT
    (VARCHAR(10),
    mt.OPacket_TransactionTime, 102)
    AS [Date],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
    THEN 1 ELSE 0
    END) AS [A - HighC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Medium Comfort%')
    THEN 1 ELSE 0
    END) AS [A - MediumC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Low Comfort%')
    THEN 1 ELSE 0
    END) AS [A - LowC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Low Risk%')
    THEN 1 ELSE 0
    END) AS [D - LowR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Medium Risk%')
    THEN 1 ELSE 0
    END) AS [D - MediumR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Risk%')
    THEN 1 ELSE 0
    END) AS [D - HighR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('BL(%')
    THEN 1 ELSE 0
    END) AS [BL Count],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('WL(%')
    THEN 1 ELSE 0
    END) AS [WL Count],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Marked as Touched%')
    THEN 1 ELSE 0
    END) AS [Touched by DRT],
    COUNT
    (mt.csnTransactionId)
    AS [Sent to DRT]
    FROM MatchedTransaction mt
    WITH (NOLOCK)
    LEFT
    JOIN CustomerComment cc
    WITH (NOLOCK)
    ON (mt.csnTransactionId
    = cc.SenderMTCN
    AND cc.InsertDate
    BETWEEN @StartDate AND
    DATEADD (D, 1, @EndDate)

    I have adjusted this as  
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
    AND cc.Comment
    LIKE ('%BL(%')THEN 1
    ELSE 0 END)
    AS hcbl,
    Still no result

  • SQL query - using COUNT

    I have a database structure like this:
    Table - lodges
    LodgeID (PK)
    Lodge
    etc
    Table - scores
    ScoreID (PK)
    Score
    CategoryID
    LodgeID (FK)
    I'm trying to return results in the form:
    LodgeID, Lodge, Category, Number of Scores in that Category, Average Score in that Category
    So for example, if I had:
    lodges
    LodgeID, Lodge
    1, Lodge One
    2, Lodge Two
    scores
    ScoreID, Score, CategoryID, LodgeID
    1, 3, 101, 1
    2, 5, 101, 1
    3, 7, 101, 1
    4, 10, 102, 2
    5, 20, 102, 2
    6, 30, 102, 2
    7, 40, 102, 2
    I'd like to return:
    1, Lodge One, 3, 5
    2, Lodge Two, 4, 25
    I've been trying things like:
    SELECT COUNT(ScoreID) as scoreCount, AVG(Score) as AverageScore, Lodge FROM scores_temp INNER JOIN lodges_temp ON scores_temp.LodgeID = lodges_temp.LodgeID
    Without any success. Any pointers would be much appreciated.

    Ignore that - just needed to add a GROUP BY clause.

  • SQL QUERY FOR COUNT

    HI all,
    I need to know the no of records in a table in sap..
    can anybody help on this how to get the count of the records.?
    thanks in advance
    kp

    Hi KP,
    You can code it this way
    data var type i.
    select count(*) from ztable into var.
    write : var.
    Here
    var
    gives you teh number of records.
    The advantage of this is that you don't have to bring all the records into the application server, just to count the records. The n/w traffic is hence reduced.
    Regards
    Anil Madhavan

  • SQL Query...number to time

    Hi,
    I want to know how to a convert number (say, 54678) into hh:mi:ss format.
    Any help.
    Thanks.

    You can test/troubleshoot it. This may or may not be perfect, you need to reverse engineer it and find (any) mistakes/logic errors. Hint: there is one.
    set serveroutput on
    create or replace procedure get_time (sod in number) as
      v_diff number;
      v_current number;
      v_date date;
    begin
      v_current := to_number(to_char(sysdate,'SSSSS'));
    --  dbms_output.put_line('v_current is '||v_current);
      v_diff := v_current - sod;
    --  dbms_output.put_line('v_diff is '||v_diff);
      --evaluate the difference
      if v_diff < 0 then
        --means number of seconds is in the future
        v_date := sysdate - v_diff/86400;
      elsif v_diff > 0 then
        --means sod is in the past
        v_date := sysdate + v_diff/86400;
      else
        --means you got lucky
        v_date := sysdate;
      end if;
      dbms_output.put_line('At the tone, the time is '||to_char(v_date,'HH:MI:SS PM'));
    end;
    exec get_time(54678);
    At the tone, the time is 03:11:18 PM
    PL/SQL procedure successfully completed.Message was edited by:
    stevencallan
    Message was edited by:
    stevencallan

  • SQL query that counts records??

    I have an equipment maintenance table and I'm trying get a list of unique equipment IDs along with a count of total maintenance records for that peice of equipment.
    Say for instance the table is set up like this
    maintenance_table
    equipment_id varchar(20)
    maintenance_date DATE
    maintenancelog_id varchar(20)
    I'm trying to do something like
    SELECT DISTINCT equipment_id, (select count(*) from maintenance_table where equipment_id = "the one for this row"), maintenance_date from maintenance_table WHERE
    condition = 'something';
    The subquery works fine when I hard code an id in it, but I need it to be dynamic and show the correct count for each row.
    Can anyone help?
    Thanks,
    George

    SELECT equipment_id, count(*) from maintenance_table group by equipment_id;

  • SQL query - show integer number as text

    Hello,
    how can I reads data from the db that is either "-1" or "1" (it's define as integer)
    and display as 'YES' or 'NO' ?
    Thank you
    Gian

    Hi,
    You can also do this:
    select decode(<your_column>,-1,'YES','NO') from <your_table>;
    Peter D.

  • Creating a directory via a jsp page sql query return

    Is it possible to create a directory based on the results of a sql query?
    i.e.
    My sql query returns application number 1234 for a building application (BC for short).
    Is it possible to create a directory /BC/1234
    It is then proposed to use an iframe to look into the directory so users can place and access scanned documents which are captured during the approval process.
    If so how?
    An example would be great.
    Jason

    Sorry hope your still around I've been away for a while. We've created a samber share to the file server where the documents are stored and mounted it within the web file directory. It works ok if there is an existing directory but if there isn't we want it to be created when the page looks for the folder. I've done this with an asp page it basically did a directory exist test first then create folder if it didn't. The problem is can't find an example of how to do the directory exist test then directory create syntax so an example of both would be great

  • Count the number of columns return in an user-input sql query

    I need to do something like this
    I let an user input a sql query and then execute it
    assuming the sql query is always correct, it will return a Resultset
    then a table will pop up to accomodate the number of columns the resultset will produce
    i'm stuck at the part on how to check how many columns of data will be return in the resultset

         ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
         ResultSetMetaData rsmd = rs.getMetaData();
         int numberOfColumns = rsmd.getColumnCount();

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 rows and 5 have "notes". I should show 1,2,3,4,5 in the notes column for those rows and the number gets displayed as a link to another section listing the notes 1 through 5.
    I was thinking of creating a hidden page item as the counter with value of 0 and then in my query doing counter+1 but i'm not sure how to do this or if i can do that...
    If anyone can help or have any other ideas I would really appreciate it!!
    Thanks,
    Hindy

    Well, I'm doing this in VB and the subquery is dynamic. I'm passing an ADO recordset to a routine that sets up a listview to display the results. The number of columns selected can vary. My idea was to size the columns appropriately based on the size of the data. Within the display routine I could:
    sql = "SELECT "
    for i = 0 to oRS.Fields.Count - 1
    sql = sql & "MAX(LENGTH(" & i & ")), "
    next 'i
    sql = sql & "FROM (" & oRS.Source & ")"

  • Count number rows in multiple tables from one query

    Hi
    I was wondering if its possible to have a single query return the number of lines in multiple tables, for example i have the tables
    foo1
    pk_foo1
    and
    foo2
    pk_foo2
    They are not joined together by any contraints. So the pseudo code for the query would be something like
    SELECT numrows(pk_foo1), numrows(pk_foo2) FROM foo1, foo2
    Thanks!

    without a join you get a cartesian product for the query:
    SQL> select count(d.deptno),count(e.deptno)
      2  from dept d,emp e
      3  /
    COUNT(D.DEPTNO) COUNT(E.DEPTNO)
                105             105so you need to do a bit of trickery
      1  select a.cnt,b.cnt
      2  from
      3  ( select count(d.deptno) cnt from dept d ) a,
      4* ( select count(e.deptno) cnt from emp e) b
    SQL> /
           CNT        CNT
             7         15
    SQL> select count(*) from dept;
      COUNT(*)
             7
    SQL> select count(*) from emp;
      COUNT(*)
            15

  • Get Number of rows from a sql query.

    I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
    Is there an easy way to do this without looping through the table?
    Thanks Jasper

    Hi Jasper,
    You can use the XPATH count function similar to  this:
    GetTagList.Results{count(/Rowsets/Rowset/Row)}
    Kind Regards,
    Diana Hoppe

Maybe you are looking for

  • How to print selection only

    I saw this question on another forum and realized that I have no idea how to print 'selection only'. The only options in the file>print menu are for the pages desired. I see no way to print only the selected portion of a page. There must be a way, bu

  • Generic Connectivity - can't name an existing column in a query

    I set up my Oracle 8.1.6 database server to support an ODBC connection ( using MERANT DataDirect Connect ODBC 3.70) to an external MSSQLServer. The connection works but I have the following problem: select * from KUAF@hsodbc; --> works fine select na

  • CCM 2.0: Field price unit in the csv file

    Hello Colleagues, We have SRM 5.5 with CCM 2.0 We would like to know the name of the column field in the csv file to indicate the price unit. For example, we have articles that the price is 93€ / 1.000 Units. We would like to know the name of the fie

  • Removing USB wakes computer from sleep.

    I just bought a new monitor to use with my PowerBook. The monitor is a Dell with built in USB plugs. The problem is that when i put the computer to sleep, the monitor(like almost all monitors) goes in to a "power-save" mode (where it doesnt display a

  • Extending AD schema - any hidden gotchas?

    I've had a fairly positive experience with the triangle (up until 10.6 anyway), but I'm considering ditching the Xserve and going the schema route. Any major caveats to watch out for? Possible things to go wrong? TIA! FZ