Query in SQL to display the count of all the records, but where condition is present

Hi all
I have the situation where I have to show number of all records in all the particular period but where the condition type condition must be present:

Please find below sample data:
PERIOD_ID TYPE MV_COUNT IS_FLAG
20110401 AM 1 0
20110401 AM 1 0
20110401 MS 29 0
20110501 MS 1 0
MS 14 20110601 0
20110701 MS 2 0
20110401 MS 1 0
20110401 AM 2 0
20110401 AM 69 0
20110401 AM 2 0

Finally, I need to type = MS
(i) is_flag total count for all periods
(II) for the period = 20110501 this is the mv_count

I need to use the unique table time (i.e. outer joins self-join not)
I tried using the partition by clause, but it will filter the data.

See you soon,.
SP

842106 wrote:
Finally, I need to type = MS
(i) is_flag total count for all periods
(II) for the period = 20110501 this is the mv_count

I need to use the unique table time (i.e. outer joins self-join not)
I tried using the partition by clause, but it will filter the data.

select sum(is_flag) is_flg_count,
         sum
            (
             case when period = 20110501 then mv_count else 0 end
            ) mv_cnt_for_20110501
from your_table
where type = 'MS';

Tags: Database

Similar Questions

  • SQL to display the results if the number of output is below a limit

    I have a requirement where I can display the SQL result set if the number of records output is 1000 or less than that... otherwise raise a user-defined exception, say "Please change the search criteria. I can achieve this by GET the the number of SQL rows first and then re-run the same SQL to display the data if the number of rows is less than 1001. Could someone let me know if this is possible without re - run the SQL several times as the SQL is the query intensive re-source

    Hello

    You can try in bulk collect into a collection.

    If the number of rows in the collection is less than 1000 triggers an application error or return results, if it is greater than 1000

    If this is suitable for your needs, please post more information on the system requirements.

    Kind regards

    Cool

  • SQL to display the Mon - Sun

    I need a SQL to display the Mon - Sun in a week when enter a date. If I give 24 March 2011 "I want Mon - Sun displayed dates IE from March 21, 2011 to March 27, 2011."

    Even if this question is asked a lot times I decided to post this time.

    Next time if you could search the forum it will be very much appreciated.

    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    
    SQL> alter session set nls_Date_Format = 'DD-MON-YYYY';
    
    Session altered.
    
    SQL> with t
      2  as
      3  (
      4   select next_day(to_date('&Enter_Date','dd.mm.yyyy') - 7, 'SUN') start_date from dual
      5  )
      6  select start_date + level from t
      7  connect by level <= 7
      8  /
    Enter value for enter_date: 24.03.2011
    old   4:  select next_day(to_date('&Enter_Date','dd.mm.yyyy') - 7, 'SUN') start_date from dual
    new   4:  select next_day(to_date('24.03.2011','dd.mm.yyyy') - 7, 'SUN') start_date from dual
    
    START_DATE+
    -----------
    21-MAR-2011
    22-MAR-2011
    23-MAR-2011
    24-MAR-2011
    25-MAR-2011
    26-MAR-2011
    27-MAR-2011
    
    7 rows selected.
    

    Thank you

    REDA

  • Computer will display the text but not the graphics

    I have a computer that is running Windows 7 Pro 64 bit that will display the text, but will not be graphic print (what I get is several pages of garbled text and what looks like Morse code).

    The problem is the same with a HP Officejet Pro 6230 or an Officejet Pro 8100.

    The problem occurs if I am connected with a domain users account or the local administrator account.

    The problem occurs using the re-discovery of HP network port monitor or the standard TCP/IP port.

    Two other computers connected to the printer and also running Windows 7 Pro 64 bit, you do not have the problem.

    HP printing and doctor Scan didn't find any problem and is not the problem of printer Microsoft Fixit fix anything.

    I will try to assign another driver by following the instructions at:

    http://h30434.www3.HP.com/T5/printer-all-in-one-software-drivers/how-to-assign-alternate-print-drivers-in-different-versions/TD-p/1957011

    but I do not know what driver to use.

    This Technet article:

    http://blogs.technet.com/b/perfguru/archive/2008/08/06/print-spooler-crash-troubleshooting-steps.aspx

    suggests that a third-party port monitor may be to blame. I tried to remove the rediscovery of HP Network Monitor, but I get an error and I can't remove it. As far as I can tell, this is the third port only installed on the computer monitor.

    I have searched this forum, but could not find a similar problem that has a solution.

    What other information should I provide?

    Thank you!

    Jeffrey Pike

    Groton public library

    ELSA:

    Further investigation of this issue today, I learned that probably, printing problems don't were not due to the computer or printer, but a bad pass that the computer is plugged into. I ordered a new switch, and I hope that it will be the end of my troubles. Thank you for the help that is available to you.

    Jeffrey Pike

    Groton public library

  • Adobe handler will not update. The Manager displays the updates but won't go further. What could be wrong?

    my adobe handler will not update. Adobe manager displays the updates but won't go further. What could be wrong? There is nothing wrong with my computer, although there may be a setting that needs to change, but I'm guessing.

    Try direct updates

    https://www.Adobe.com/downloads/updates/

    updates CC:
    http://prodesigntools.com/Adobe-CC-updates-direct-links-Windows.html
    http://prodesigntools.com/Adobe-CC-updates-direct-links-Mac.html

    CC updates of 2014:
    http://prodesigntools.com/Adobe-CC-2014-updates-links-Windows.html
    http://prodesigntools.com/Adobe-CC-2014-updates-links-Mac.html

    CC updates to 2015:
    http://prodesigntools.com/Adobe-CC-2015-updates-links-Windows.html
    http://prodesigntools.com/Adobe-CC-2015-updates-links-Mac.html

  • I can't move my documents in folders - I drag them on the record, but then nothing happens

    I can't move my documents in folders - I drag them on the record, but when I communicated nothing has changed and that they remain in the form of separate documents - can anyone help?

    Hi fulham404,

    I understand that you can not copy the files to a folder. I'm not sure where the destination is, but I would recommend that you look at the permissions for your destination file. As long as you are authorized, you should be good to go.

    Set permissions for the items on your Mac OS X El Capitan:
    https://support.Apple.com/kb/PH21997

    Let me know if it helps. If it is not the case, give a little more detail as to where you copy your files.

    Nice day

  • Try to set up my Elipse on my computer. Have the microSDHC card/w adapter. Where should I go from here. The chip is in the adapter but where to insert into the computer to get results!

    Try to set up my cell phone to Elipse with microSDHC card/w adapter.  The chip is in the adaptor, but where can I insert the adapter in the computer.  Have an inspiron 531.  "Any help would be greatly apprecialted!   =}

    Hi NancyDolezal,

    Connect the phone via USB. You must insert it into a USB port and check if it detects is.

  • I had to reset my computer and now I am unable to install Photoshop elements 12.0. I have the record, but can not find where to install

    I had to reset my computer and now I am unable to install Photoshop elements 12.0. I have the record, but can not find where to install

    Hello

    Please Photoshop elements help | Download Photoshop Elements | 10, 11, 12, 13

    Hope that helps!

    Kind regards

    Sheena

  • Hi - I have an old Adobe Audition 1.5 and I used to be able to hear that I was recording. After the update of computer and reload Adobe Audition 1.5, can no longer hear the recording, but only on playback. Please notify.

    Hi - I have an old Adobe Audition 1.5 and I used to be able to hear that I was recording. After the update of computer and reload Adobe Audition 1.5, can no longer hear the recording, but only on playback. Please notify.

    Monitoring is done through your audio device, no hearing. When you updated your PC, playback of the audio device settings would have been reset. One of them includes the follow-up of the input jack, and that's what you need to restore. Since we do not know which audio device you use, it's all that we can tell you, except that if it is a device internal, you will need to open the volume control options and he change it. It depends on the good OS versions...

  • Excuse me, but I only am not able to cancel my plain... I already saw the tutorial, but where there is the choice to cancel the plain I see only a white window...

    Excuse me, but I only am not able to cancel my plain... I already saw the tutorial, but where there is the choice to cancel the plain I see only a white window...

    This is an open forum, not the Adobe support... You need Adobe support to cancel a subscription

    -Cancel http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html

    -or http://helpx.adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

    -or by phone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • the variable name of database query to SQL Server using the Oracle database link

    Hi all

    I have an ApEx 4.1 application running on x 64 (11.2.0.1) 11g on Windows Server 2008 x 64, and I have a few points of data integration with SQL (2005 and 2008) server that I need to create. I have configured the database with dg4odbc link and it works perfectly... I can run queries on the SQL Server database without any problem using the database link.

    However, there is a scenario where the SQL Server database name is dynamic, and I need to generate on the fly in a PL/SQL block and then use it in a query dynamic SQL (all this in the ApEx). It of wherever I meet problems... when I asked the default database that is based on the ODBC connection and I don't have to specify the name of the database, no problem. But when I need access to one of the several other databases by default, I received the error "invalid table.

    It works well:* (note that 'fv' is the name of my database link)

    v_query1: = "select 'Release Date' from dbo." Schedules@FV where dbo. Annexes. "" SchedID "=: calendar";
    EXECUTE IMMEDIATE v_query1 in rel_date using the grid.




    I then take this rel_date variable, convert a varchar2 (rel_date_char), then use it as the name of the database in the following query...


    _ It returns an error(error ORA-00903: invalid table name)

    v_query2: = "select"PARTNO": rel_date_char.dbo.ProdDetails@fv where 'SchedID' =: calendar and"UnitID"=: unit"
    and 'MasterKey' =: master and "ParentKey" =: parent';

    EXECUTE IMMEDIATE v_query2 in part_number using planning, master, parent unit;



    I also tried using all of the following conditions without result:

    "select"PARTNO"of" | : rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"of" | rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"of" | @rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"in @rel_date_char.dbo.ProdDetails @fv where 'SchedID'..."


    Is it possible to do it in PL/SQL?

    Thanks for any help!
    -Ian C.

    Published by: 946532 on July 15, 2012 19:45

    Just did a test using passthrough:

    SQL > set serveroutput on
    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5. start
    c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, "select count (*) from EMP");
    8 LOOP
    9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    10 output when nr = 0;
    11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    12 dbms_output.put_line (val);
    13 end of loop;
    14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    15 end;
    16.
    24576

    PL/SQL procedure successfully completed.

    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5. start
    c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' select count (*) from dbo.) EMP');
    8 LOOP
    9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    10 output when nr = 0;
    11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    12 dbms_output.put_line (val);
    13 end of loop;
    14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    15 end;
    16.
    24576

    PL/SQL procedure successfully completed.

    So all 3 ways work for me.

    Published by: kgronau on July 23, 2012 10:08

    Now, using the variables to make the selection:

    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5 tabname varchar2 (20): = 'EMP ';
    6 ownr varchar2 (20): = "dbo."
    7 dbname varchar2 (20): = "door";
    Start 8
    c: 9 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    10 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' SELECT count (*) FROM ': dbname: '.) ' || ownr | '.'|| tabname | ") ;
    11 LOOP
    12 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    13 when the exit nr = 0;
    14 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    15 dbms_output.put_line (val);
    16 end loop;
    17 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    18 end;
    19.
    24576

    PL/SQL procedure successfully completed.

    => instead of executing the statement using the "execute Immediate" we use the PASTHROUGH package to pass the statement to SQL Server.

    Published by: kgronau on July 23, 2012 10:10

  • How to use a parameter query to select and display the data in the table of the façade

    Hiiiiii

    I am using Access 2007 database
    I want to select the specific data in the database using control of the chain as 'select product, size, weight of ProductInfo where barcode (chain control) =?'  and also display the same table of façade.

    I use the connected database toolkit.
    I saw the example of the parameterized insert, but it did not help to use parameterized select query, as well as to display data of parameterized select query.

    I looked for example on parameterized select query, but I don't have any.
    So pls guide me how to do this. I would like to know the other method (if any) that the use of parameter query to perform the same thing.
    If possble pls share a vi reference.
    Thank you!!!

    HII szewczak
    Thanks for the reply
    but I did not getsolution in one of your shared links
    My problem is solved. There is no need to use the parameter query to select control values
    In my case I want to display data from database where bar code is even entered by the user
    I use the data function DB TOOL CHOOSE and create the condition of chain based on concatenation of strings

  • How to display the records from a query in the non-base data field

    Hello

    I have a problem:
    I have a query with a lot of tables and column 6 (select a, b, c, d, e, f x, y, z, t, s, g where the conditions) and I use 3 parameters.
    I create 3 settings: datai,: dataf and: partner and a button with a trigger when the button is pressed.
    Then a create a block manually with six field non-database a1, b1, c1, d1, e1, f1.
    Now, I want to display all the records in my query in a1, b1, c1, d1, e1, f1 where a1 = a, b1 = b, etc. and all the records (if I have 20 record, it will display 20 records in the non-base data field) when I press the button.

    How I did it:
    I create a cursor with the query, and then
    start the open cursor
    loop
    Fetch cursor in: a1,: b1,: c1: d1: e1,: f1;
    end loop;
    close the cursor;
    end;

    It displays a single record in a1, b1, c1 only, and it must display 100 records and date for all fields.

    Can someone help me with this problem?
    Thank you.

    Published by: 928437 on October 1, 2012 02:55

    Creating a view and the query in a database block are a great solution.

    To use the block non-base of data:
    You are missing the most important Next_Record; command.

     Begin
    Go_block('X'); -- block X is the non-database block
    Clear_Block(No_Validate);
    open cursor X1;
    loop
    If :System.Record_status != 'NEW' then
    Next_Record;
    End if;
    fetch X1 into :a1,:b1,:c1,:d1,:e1,:f1;
    Exit when X1%NOTFOUND;
    end loop;
    close X1;
    end;

  • Error SQL query while trying to fetch the record that has MAX Effective_Date

    Hello

    Could you please suggest me on request below.
    I need to select the record which is having Maximam effectivity_date.
    Below a no not gives a group of expressin

    SELECT safety_stock_quantity
    OF mtl_safety_stocks
    WHERE inventory_item_id = 936
    GROUP BY safety_stock_quantity
    After having effectivity_date = MAX (effectivity_date);



    Thank you
    Pravin

    855902 wrote:
    Hello

    Could you please suggest me on request below.
    I need to select the record which is having Maximam effectivity_date.
    Below a no not gives a group of expressin

    SELECT safety_stock_quantity
    OF mtl_safety_stocks
    WHERE inventory_item_id = 936
    GROUP BY safety_stock_quantity
    After having effectivity_date = MAX (effectivity_date);

    Thank you
    Pravin

    SQL> select * from emp where mep_hiredate = (select max(mep_hiredate) from emp);
    
        EMP_ID EMP_NAME   EMP_SAL                    MEP_HIREDATE
    ---------- ---------- ------------------------------ -------------------
          COMM
    ----------
          1 ED           2                     2010-12-20 09:40:50
          2
    
  • Using SQL to display the date range

    Gurus,

    I have a sql statement such as
    select MIN(HIREDATE), MAX(HIREDATE) FROM EMP WHERE DEPTNO = 30
    My output looks like
    MIN(HIREDATE)     MAX(HIREDATE)
    
    12/30/1998        12/30/2001
    Based on the values of MIN (HIREDATE), MAX (HIREDATE) values
    I need a SQL to generate the output as

    30/12/1998
    30/01/1999
    28/02/1999
    ---
    ---
    until the Max value (HIREDATE)

    In February, we have 30 days, in this case to the last day of the month.

    Thanks for the great help
    C 007

    Hello

    put my post to correct and others with useful, please

    Is salim.

Maybe you are looking for

  • iPhone WiFi sharing

    Is it possible to share the connection Wi - Fi (not cell) of a 6 s iPhone more (iOS 9.3.3) to a MacBookPro (retina, mid-2012, i7, 16GB) via USB? For some reason, I need the MacBook to connect to two different wi - fi (LAN1 and LAN2) at the same time.

  • I tried to install iOS 9.2 on my iPhone 6s, but he repeated to me that "can not update right now, try again later".

    I currently have an iPhone 6s 126 GB with iOS installed 9.1. My problem started when my touch id does not work at all. I tried to reset my iPhone several times and it just says: the contact id can not be configuerd. Then, after some research, I read

  • Black ink cartridge of will have no impression

    I'm just looking all my cartridges and color and black works does not; he tries, but just bery faded or not at all. I did deep cleaning and still get the same results. is good that my ctidge is too full?  Help I can't print... Thank you Caught up in

  • Adobe Photoshop Setup error

    Hello!We have a problem with the installation of Adobe Photoshop.OC - Windows 7 Professional 64-bit.When we try to istall it, we get an error C301 - lack of update needed. But we already install this update. Please, say, how to solve this problem!

  • the list of users to Weblogic

    HelloCan someone please help me get all weblogic users using the SQL query? Is this possible? I want to do a LOV ADF based on these users form. Can someone help me please in this matter