Get count in Query

Hello all,
How can i get total number of count in the below query...its always giving 1 for each rows..
Cover countofcovers
12345 1
43564 1
43535 1
i need 3 as count ..any help
select cover,count(*) countofcovers from ( SELECT A.COVER_NUMBER cover
     FROM HL01unit.COVER A,
          HL01unit.CLIENT_STAGING G,
          HL01unit.COVER_CATEGORY F
     WHERE A.POLICY_NUMBER ='10000142'
     AND F.COVER_NUMBER = A.COVER_NUMBER
AND G.POLICY_NUMBER = A.POLICY_NUMBER
     AND G.COVER_NUMBER = A.COVER_NUMBER
     AND A.PARENT_COVER_NO IS NULL
     AND UPPER(G.SURNAME) LIKE UPPER(RTRIM('R')) CONCAT '%'
UNION
     SELECT DISTINCT(A.PARENT_COVER_NO) cover
     FROM HL01unit.COVER A,
          HL01unit.CLIENT_STAGING G,
          HL01unit.COVER_CATEGORY F
     WHERE A.POLICY_NUMBER ='10000142'
     AND F.COVER_NUMBER = A.COVER_NUMBER
AND G.POLICY_NUMBER = A.POLICY_NUMBER
     AND G.COVER_NUMBER = A.COVER_NUMBER
     AND A.PARENT_COVER_NO IS NOT NULL
     AND UPPER(G.SURNAME) LIKE UPPER(RTRIM('R')) CONCAT '%'
) yTable group by cover

try union all instead of union
Peter
maybe a small example to explain that the inner query is
wrong and not the group by
select 1 counter from dual;
COUNTER
1
1 row selected.
select counter, count(*) from (
select 1 counter from dual
union
select 1 counter from dual)
group by counter;
COUNTER COUNT(*)
1 1
1 row selected.
select 1 counter from dual
union all
select 1 counter from dual;
COUNTER
1
1
2 rows selected.
select counter, count(*) from (
select 1 counter from dual
union all
select 1 counter from dual)
group by counter;
COUNTER COUNT(*)
1 2
1 row selected.
Message was edited by:
Peter Verhaegen

Similar Messages

  • Getting Counts with single query

    HI,
    I need help in writing a query that gets account counts in a single query,
    CREATE TABLE ACCOUNTINFO(     
    ACCOUNTID VARCHAR2(20 BYTE) NOT NULL,
    ACCOUNTNO VARCHAR2(10 BYTE) NOT NULL,
    LAST_DEPOSIT_DATE DATE,
    BALANCE NUMBER(10,0));
    I have a table like above and I am trying to write a query that gets
    Count of accounts with deposits made in last 1 month,
    Count of accounts with deposits made in last 2 months
    Account Count with balance > 0,
    Also, I need to join this ACCOUNTINFO with ACCOUNTMAIN to get name etc details
    CREATE TABLE ACCOUNTINFO(     
    EMPID VARCHAR2(20 BYTE) NOT NULL,
    FNAME VARCHAR2(30 BYTE) NOT NULL,
    MNAME VARCHAR2(30 BYTE),
    LNAME VARCHAR2(30 BYTE) NOT NULL,
    DOB DATE,
    ACCOUNTID VARCHAR2(20 BYTE));
    Question, how to write a query since I getting too-many counts (I have only 3 in sample above, actual goes on like 3-6, 6-9 etc).

    SELECT SUM  (CASE WHEN LAST_DEPOSIT>=ADD_MONTHS(SYSDATE,-1) THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_LAST_MONTH,
           SUM  (CASE WHEN LAST_DEPOSIT>=ADD_MONTHS(SYSDATE,-2) THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_LAST_TWO_MONTHS,
           SUM  (CASE WHEN BALANCE>0 THEN
                   1
                 ELSE
                   0
                 END
                ) COUNT_BALANCE_GREATER_ZERO
      FROM ACCOUNTINFO

  • How to get count of all records of all entities in CRM Online

    Hi,
     I want to get count of all records entitywise in dynamics CRM 2013 online. I know we can count the records in CRM on-premise using a SQL query in report. Earlier I wrote a SSRS report to count the records in a CRM entity wise  as displayed in
    the screenshot below..
    Can someone suggest me a good approach to implement the same in CRM Online. 
    Thanks
    Pratibha Singh

    Hello,
    In a CRM Online environment, you need to create reports based on Fetch XML. Take a look at this link to create a Fetch XML query with aggregates: https://msdn.microsoft.com/en-us/library/gg309565.aspx?f=255&MSPPError=-2147217396#count .
    Here is an example to create a report in an online environment: http://edwardsdna.com/2012/12/03/crmonline-report/
    Hope it helps,
    Kind regards

  • How to get count as 0 for records not in table

    Hi All,
    I have requirement where I need count of records in the table based on ids. Example query below
    SELECT empid ,
    nvl(COUNT(id), 0) empcount
    FROM employee
    WHERE empid IN(1, 2, 4, 5)
    GROUP BY empid
    In the table only record for "empid=2" is present so I get count 1 for it. But with it I should get count as 0 for non existing records. Expecting below output
    empid | empcount
    1 | 0
    2 | 1
    4 | 0
    5 | 0
    Appreciate your help and Thanks in advance.
    Regards.
    Ashish

    e.g.
    SQL> select column_value deptno, count (deptno)
    from emp, table (sys.odcinumberlist (10, 20, 100))
    where deptno(+) = column_value
    group by column_value
        DEPTNO COUNT(DEPTNO)
            10             3
            20             5
           100             0
    3 rows selected.

  • Get-Counter : The \\ServerNameHere\\SQLSERVER:Locks(_Total)\Lock Waits/sec performance counter path is not valid.

    I have the following code:
    Import-Module "sqlps" -DisableNameChecking
    #####http://www.travisgan.com/2013/03/powershell-and-performance-monitor.html
    function ExtractPerfmonData 
        param(
            [string]$server,
            [string]$instance
        [Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet]$collections
        $monitorServer = "MonitoringServerNameHere"
        $monitorDB = "MonitoringDatabaseNameHere"
        $counters = @(
            "\$($instance):Memory Manager\Memory Grants Pending",
            "\$($instance):Memory Manager\Target Server Memory (KB)",
            "\$($instance):Memory Manager\Total Server Memory (KB)",
            "\$($instance):Buffer Manager\Buffer Cache Hit Ratio",
            "\$($instance):Buffer Manager\Checkpoint pages/sec",
            "\$($instance):Buffer Manager\Page Life Expectancy",
            "\$($instance):General Statistics\User Connections",
            "\$($instance):General Statistics\Processes Blocked",
            "\$($instance):Access Methods\Page Splits/sec",
            "\$($instance):SQL Statistics\Batch Requests/sec",
            "\$($instance):SQL Statistics\SQL Compilations/sec",
            "\$($instance):SQL Statistics\SQL Re-Compilations/sec",
            "\$($instance):Locks(_Total)\Lock Waits/sec"
        $collections = Get-Counter -ComputerName $server -Counter $counters -SampleInterval 1 -MaxSamples 1
        $sampling = $collections.CounterSamples | Select-Object -Property TimeStamp, Path, Cookedvalue
        $xmlString = $sampling | ConvertTo-Xml -As String
        $query = "dbo.usp_InsertPerfmonCounters_SQLServer '$xmlString';"
        Invoke-Sqlcmd -ServerInstance $monitorServer -Database $monitorDB -Query $query
    #####ExtractPerfmonData -server "YourRemoteServerName" -instance "MSSQL`$SQLTest"
    ExtractPerfmonData -server "ServerName1Here" -instance "SQLSERVER" 
    ExtractPerfmonData -server "ServerName2Here" -instance "SQLSERVER"
    ExtractPerfmonData -server "ServerName3Here" -instance "MSSQL`$InstanceNameHere"  
    ExtractPerfmonData -server "ServerName4Here" -instance "SQLSERVER" 
    (I have 93 instances listed; here I just gave a sample of 4.)
    For only one instance I get the following error message:
    Get-Counter : The
    \\ServerNameHere2\\SQLSERVER:Locks(_Total)\Lock Waits/sec performance counter path  is not valid.
    All of the instances should have been set up the same, so I am confused as to why this error only occurs on this one instance.  I do not know where to look.  Has anyone ever seen this type of error before?
    lcerni

    Here is the output of the first script:
    CounterSetName                                                                                                                     
    ...       (eliminating non sql server counters here)              
    SQLAgent:Alerts                                                        
    SQLAgent:Jobs                                                          
    SQLAgent:JobSteps                                                        
    SQLAgent:Statistics                                      
    SQLServer:Access Methods                                                                                          
    SQLServer:Availability Replica  SQLServer:Backup Device                                                                                                            
    SQLServer:Batch Resp Statistics                                                                                                    
    SQLServer:Broker Activation                                                                                                        
    SQLServer:Broker Statistics                                                                                                        
    SQLServer:Broker TO Statistics                                                                                                     
    SQLServer:Broker/DBM Transport                                                                                                     
    SQLServer:Buffer Manager                                                                                                           
    SQLServer:Buffer Node                                                                                                              
    SQLServer:Catalog Metadata                                                                                                         
    SQLServer:CLR                                                                                                                      
    SQLServer:Cursor Manager by Type                                                                                                   
    SQLServer:Cursor Manager Total                                                                                                     
    SQLServer:Database Mirroring                                                                                                       
    SQLServer:Database Replica                                                                                                         
    SQLServer:Databases                                                                                                                
    SQLServer:Deprecated Features                                                                                                      
    SQLServer:Exec Statistics                                                                                                          
    SQLServer:FileTable                                                                                                                
    SQLServer:General Statistics                                                                                                       
    SQLServer:Latches                                                                                                                  
    SQLServer:Locks                                                                                                                    
    SQLServer:Memory Broker Clerks                                                                                                     
    SQLServer:Memory Manager                                                                                                           
    SQLServer:Memory Node                                                                                                              
    SQLServer:Plan Cache                                                                                                               
    SQLServer:Query Execution                                                                                                          
    SQLServer:Replication Agents                                                                                                       
    SQLServer:Replication Dist.                                                                                                        
    SQLServer:Replication Logreader                                                                                                    
    SQLServer:Replication Merge                                                                                                        
    SQLServer:Replication Snapshot                                                                                                     
    SQLServer:Resource Pool Stats                                                                                                      
    SQLServer:SQL Errors                                                                                                               
    SQLServer:SQL Statistics                                                                                                           
    SQLServer:Transactions                                                                                                             
    SQLServer:User Settable                                                                                                            
    SQLServer:Wait Statistics                                                                                                          
    SQLServer:Workload Group Stats                                                                                                     
    ...       (eliminating non sql server counters here)
    lcerni

  • Logging level to get the physical query

    Hi All,
    Can anyone let me know , what log level i have set it up, so that I can get the physical query for BI Answers request.
    Thanks
    S

    hi,
    Logging Levels
    Level 0
    No logging.
    Level 1
    Logs the SQL statement issued from the client application.
    Logs elapsed times for query compilation, query execution, query cache processing, and back-end database processing.
    Logs the query status (success, failure, termination, or timeout). Logs the user ID, session ID, and request ID for each query.
    Level 2
    Logs everything logged in Level 1.
    Additionally, for each query, logs the repository name, business model name, presentation catalog (called Subject Area in Answers) name, SQL for the queries issued against physical databases, queries issued against the cache, number of rows returned from each query against a physical database and from queries issued against the cache, and the number of rows returned to the client application.
    Level 3
    Logs everything logged in Level 2.
    Additionally, adds a log entry for the logical query plan, when a query that was supposed to seed the cache was not inserted into the cache, when existing cache entries are purged to make room for the current query, and when the attempt to update the exact match hit detector fails.
    Do not select this level without the assistance of Technical Support.
    Level 4
    Logs everything logged in Level 3.
    Additionally, logs the query execution plan. Do not select this level without the assistance of Technical Support.
    Level 5
    Logs everything logged in Level 4.
    Additionally, logs intermediate row counts at various points in the execution plan. Do not select this level without the assistance of Technical Support.
    Level 6 and 7
    Reserved for future use.
    Hope this helps,
    cheers,
    vineeth

  • GETTING COUNTS FOR EACH SSN

    I am doing a report in ORACLE REPORT WRITER. How can I get counts for each SSN. I want to check the last 7 SSNS
    and if the competence codes are different get a count for them. If the fitness codes are different get a count for them. This is for each SSN. Sometimes SSNS may have different competence codes but the fitness codes are the same. I still need counts for the competence codes. Other times the SSNS have different fitness codes but the competence codes are the same and I need counts for the fitness codes. Other times the fitness codes are different and the competence codes are different and I need counts for the fitness codes and counts for the competence codes. Here is a sample of what the report should look like:
    SSN TOTAL TOTAL
    Competence Fitness
    000000111 13 6
    000000222 6 0
    000000333 0 7
    I have everything wrapped up under one count. I don't know to change the query to display 2 separate counts.
    I have used Summary Columns but that does not work.
    I could use 2 separate querys and get counts for competence and fitness respectively but the SSNS would be out of order. The SSNS must be in order.
    Here is the query.
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt1
    FROM (SELECT distinct(t.ind_ssn), t.ind_competence_rtg_old, t.ind_competence_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_competence_rtg_old <> t2.ind_competence_rtg_new)
    GROUP BY T2.IND_SSN
    UNION
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt2
    FROM (SELECT distinct(t.ind_ssn), t.ind_FIT_rtg_old, t.ind_FIT_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_FIT_rtg_old <> t2.ind_FIT_rtg_new)
    GROUP BY T2.IND_SSN
    ORDER BY 1

    Thanks for you reply Ricardo. It does work (but only if select 1 ticket).
    My bad I only posted one Ticket Number. Actually there are lots of them ( as below). Your code take all the tickets as one tickets.
    TicketNumber
    OwningTeam
    Status
    Date
    Team Number
    123
    TEAM 1
    Pick Up
    11/12/2014
    1
    123
    TEAM 1
    Complete
    11/12/2014
    1
    123
    TEAM 2
    Pick Up
    11/12/2014
    2
    123
    TEAM 2
    Complete
    11/12/2014
    2
    123
    TEAM 2
    Resolve
    11/17/2014
    2
    123
    TEAM 2
    Complete
    11/24/2014
    2
    123
    TEAM 2
    Pick Up
    12/8/2014
    2
    123
    TEAM 2
    Complete
    12/9/2014
    2
    123
    TEAM 2
    Provide Info
    12/17/2014
    2
    123
    TEAM 1
    Pick Up
    1/8/2015
    3
    123
    TEAM 1
    Resoved
    1/8/2015
    3
    456
    TEAM 1
    Pick Up
    11/12/2014
    1
    456
    TEAM 1
    Complete
    11/12/2014
    1
    456
    TEAM 2
    Complete
    11/24/2014
    2
    456
    TEAM 2
    Pick Up
    12/8/2014
    2
    456
    TEAM 2
    Complete
    12/9/2014
    2
    456
    TEAM 3
    Pick Up
    12/17/2014
    3
    456
    TEAM 3
    Working
    12/18/2014
    3
    456
    TEAM 1
    Pick Up
    1/8/2015
    4
    456
    TEAM 1
    Resoved
    1/8/2015
    4
    789
    TEAM 1
    Pick Up
    11/12/2014
    1
    789
    TEAM 1
    Complete
    11/12/2014
    1
    789
    TEAM 2
    Complete
    11/24/2014
    2
    789
    TEAM 2
    Pick Up
    12/8/2014
    2
    789
    TEAM 2
    Complete
    12/9/2014
    2
    789
    TEAM 1
    Complete
    12/12/2014
    3
    Any work around is really appreciated.
    Thanks,
    Rajneet

  • Data not getting displayed in query

    Hi
    I have master infoobject with keyfigure units as percentage, and data is loaded and working fine.
    data is not getting displayed in query, i am getting the error message, that exception aggregation has to be maintained for 0calday.
    how do i resolve the issue
    Regards

    solved

  • How to get physical SQL query

    Hi All,
    How to get the physical SQL query for the OBIEE reports.
    Thanks in advance,
    Haree.

    Hi Anitha,
    Thanks for your reply,
    I am getting XML script in log file. (Settings > Administration > Manage Sessions > View Log).
    How to get physical SQL query ?
    Thanks,
    Haree

  • How to get the SQL Query statement of a Search Form ?

    Hi all,
    We have a requirement to send the query result of an ADF Search Form into report application (Crystal rpt).
    Crystal can accept data source as query statement. SO I think of getting the exact query statement "generated" by the ADF Search form and send it to crystal.
    Is this possible ?
    Thank you very much,
    xtanto

    Try the various get methods of the viewObject such as getQuery:
    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.2/state/content/navId.4/navSetId._/vtAnchor.getQuery%28%29/vtTopicFile.bc4jjavadoc%7Crt%7Coracle%7Cjbo%7CViewObject%7Ehtml/

  • Ordering of objects by more than one field and get counts

    i have an object visit (personid, city, street, place, date)
    A person could have visited a same place in the same strret in the same city several times on different dates.
    I have a visits 'Set' for a person and I have to get a count of visits he has done to a place..
    its basically select count(visits) group by city, street , place.
    I know to use interface comparator for a single field.. how to compare multiple fields and get counts??
    if you know abt where i can find information please let me know.
    Thanks.

    For multiple fields, your comparator compares the most significant field first. If they're unequal, it returns +/- accordingly. If they're equal, then it moves on to the next field. And so on, until, finally, if all the relevant fields are equal, then the objects are equal.
    Just like what you do when comparing, say, last names. If the first letters are unequal, you're done, else move onto the next letter, and so on..
    For the count, you wouldn't use a comparator, as that's for sorting. Exactly how you do it depends on the details of what you're storing and how, which you haven't provided.

  • How to get count of rows for a table?

    Hi,
    How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
    Regards,
    Devashish

    Hi Devashish,
    WdContext.node<Your_node_name>().size() will give you the no: of rows.
    This should be the node that is bound to the table's datasource property.
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
    You can access an attribute of a particular row as
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
    Hope this helps,
    Best Regards,
    Nibu.
    Message was edited by: Nibu Wilson

  • Can't get counter 2/3 working in simple event counting mode for NI6601

    I have been successfully been able to get counter 0 and 1 working in a simple event counting mode. But when I read Software Save register for counter2/3 it gives me garbage values. I am doing register level programming in C.
    This is the algorithm that I follow
    In initialization:
    -> Reset the Counter
    -> Write32( Clock_Config_Reg, 0x00)
    -> Write Load A and LoadB registers
    -> Write to Input Select Register with appropriate values
    -> Write16( Command_Reg, 0x0125);
    Then when I need to read the SW save register value
    -> Write to Command Register  setting the  gi_Arm bit
    -> Reading the SW save register twice
    -> If not equal ,read again
    -> Write to Command Register  disabling the  gi_Arm bit
    This works just fine for counter 0 and 1. But I can't get it working for counter 2 and 3. Are there any other registers I need to set up correctly for counter2/3. Is the default reset values of registers different for counter 2 and 3?
    Any help would be very appreciated
    Thanks

    Hello manisha,
    Is there a particular reason for using register level programming to interact with your DAQ card, rather than the DAQmx driver?  The reason I ask is because we don't support RLP at NI.  There are some manuals that have been developed, such as this one which corresponds to your card, but I am unable to offer any support after that.  If it is necessary that you must use RLP then you should post your question to the DDK forum, as they have more experience in this area.
    Regards,

  • Get-Counter path is not correct

    I'm to get this to run but keep getting this error: Get-Counter : The specified counter path could not be interpreted.
    Any insight into this issue would be appreciated.
    param($destserver, $destDB)
    $destserver = "CCIIT23"
    $destDB = "SSIMS_Prod"
    $Servers = Get-SqlData $destserver $destDb "Select ServerName From ServerNames"
    write-output $Servers
    $CounterList = Get-SqlData $destserver $destDb "Select Counter From MemoryCounterList"
    write-output $CounterList
    $Servers | Foreach-Object {
        $Serv = $_; $CounterList | Foreach-Object {
            Get-Counter -Computer $Serv -Counter $_ -SampleInterval 1

    Hi ClayRP,
    I'm not sure about the function Get-SqlData, However, Please make sure you have the right input format of the parameter -Counter in the cmdlet Get-Counter with "[\\<ComputerName>]\<CounterSet>(<Instance>)\<CounterName>".
    To get the right counter example of Memory Counter set, try to run the cmdlet below:
    (Get-Counter -ListSet memory).paths
    I hope this helps.

  • How to get the Actual Query of View Object

    Hi all,
    I have a standard. I need to modify the query of the VO attached to a picklist based on responsibility. I am able to achieve my requirement but it is getting reflected for all the responsibilities even though i extended the controller for a particular responsibility. I used setQuery() to change the query of my VO. When checking "About this page". The code i added also shown in the page. Now i want to get the actual query to the VO before the controller is extended so that i can set the modified query or actual query based on my responsibility. Kindly share your knowledge.
    Regards,
    Pradeep

    Hi,
    I guess following query will not work ,Why use 2 where clauses.
    SELECT * FROM (select NVL(VENUE_NAME,' ') "Venue",
    NVL(VENUE_CITY,' ') "City",
    NVL(COUNTRY_DESC,' ') "Country",
    EVENT_NUMBER
    From NS_EVENT_VENUE_DETAILS,NS_COUNTRY_MASTER WHERE COUNTRY_CODE = VENUE_COUNTRY) QRSLT WHERE (QRSLT.EVENT_NUMBER = 1539
    you can as following using bind variable.
    http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcquerying.htm#CEGDGIJH

Maybe you are looking for

  • Sign in with indesign CS6 in folio builder panel

    hi! I can't sign in with indesign CS6 in folio builder panel. what can a i do?? I can sign in from adobe web page, but not from indesign, and the option "updates" from "Help" menu is deactivated

  • Menu Bar Issues

    Alright so, this problem has been going on for some time with my Mac and I just decided to see if i can figure out why it's doing this. For whatever reason nothing appears on my Menu Bar. When I say nothing I mean the Time, Date, Wireless Connection,

  • Direct-connect G5 to HDTV for HD movie viewing

    I'm looking at a Toshiba HD LCD TV (1080p), and I'd like to watch movies I tape with my HDV camcorder and edit in FCE in full HD resolution. I can, of course, connect the camera directly to the TV (the HD picture is really stunning), but it's awkward

  • Firewire connection to a External Lightscribe drive by Lacie.

    I have just changed to a Mac & I am having problems with Getting my Mac to recognise a laic external drive. The system profiler Lists the firewire Device as: FireWire Bus: Maximum Speed: Up to 800 Mb/sec d2 DVDRW FW/USB: Manufacturer: LaCie Model: 0x

  • Formula Variables and their use

    I have a scenario where I have a date selection using a variable. I get from and to date defaulted to 1st day of the month and current date Next, I created a formula variable to calculate the difference between these 2 dates. I can't uses replacement