ID of the Oracle database analysis function application instance in the search status of 1

Source: Internet
Author: User

OracleDatabaseAnalysis functionsThe ID in which the search status of an application instance is all 1 is the content we will introduce in this article. Through the example in this article, let's take a look at the use of Oracle Database analysis functions, hope to help you.

Example:

1. Insert table structure and test data

Table creation:

 
 
  1. create table TAB_FXHS    
  2. (    
  3. id VARCHAR2(32),    
  4. zt VARCHAR2(2)    
  5. );   

-- Add comments to the table

 
 
  1. Comment on table TAB_FXHS
  2. Is 'the statistical Status values are all normal id ';

-- Add comments to the columns

 
 
  1. Comment on column TAB_FXHS.id
  2. Is 'Primary key id ';
  3. Comment on column TAB_FXHS.zt
  4. Is 'status ';

Insert test data:

 
 
  1. prompt Importing table TAB_FXHS...    
  2. set feedback off    
  3. set define off    
  4. insert into TAB_FXHS (ID, ZT)values ('10125', '0');    
  5. insert into TAB_FXHS (ID, ZT)values ('10161', '0');    
  6. insert into TAB_FXHS (ID, ZT)values ('10141', '0');    
  7. insert into TAB_FXHS (ID, ZT)values ('10126', '1');    
  8. insert into TAB_FXHS (ID, ZT)values ('10102', '0');    
  9. insert into TAB_FXHS (ID, ZT)values ('10103', '0');    
  10. insert into TAB_FXHS (ID, ZT)values ('10121', '0');    
  11. insert into TAB_FXHS (ID, ZT)values ('10121', '1');    
  12. insert into TAB_FXHS (ID, ZT)values ('10121', '0');    
  13. insert into TAB_FXHS (ID, ZT)values ('10121', '3');    
  14. prompt Done.   

2. Functional Requirements

In the TAB_FXHS table, ID is the key field and ZT is the state.

There may be duplicate values in the ID. Now we need to find all ID values whose ZT is all 1.

3. SQL statements for function implementation

 
 
  1. WITH ZT_PARTITION_BY_ID AS    
  2. (SELECT ID, ZT, COUNT(ZT) OVER(PARTITION BY ID ORDER BY ID) ID_ZT    
  3. FROM TAB_FXHS    
  4. GROUP BY ID, ZT)    
  5. SELECT *    
  6. FROM ZT_PARTITION_BY_ID    
  7. WHERE ID_ZT = 1    
  8. AND ZT = 1;   

The above is the whole process of analyzing the function application instance in the Oracle database to realize the ID of all 1 states. This article will introduce it here, and hope this introduction will be helpful to you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.