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:
- create table TAB_FXHS
- (
- id VARCHAR2(32),
- zt VARCHAR2(2)
- );
-- Add comments to the table
- Comment on table TAB_FXHS
- Is 'the statistical Status values are all normal id ';
-- Add comments to the columns
- Comment on column TAB_FXHS.id
- Is 'Primary key id ';
- Comment on column TAB_FXHS.zt
- Is 'status ';
Insert test data:
- prompt Importing table TAB_FXHS...
- set feedback off
- set define off
- insert into TAB_FXHS (ID, ZT)values ('10125', '0');
- insert into TAB_FXHS (ID, ZT)values ('10161', '0');
- insert into TAB_FXHS (ID, ZT)values ('10141', '0');
- insert into TAB_FXHS (ID, ZT)values ('10126', '1');
- insert into TAB_FXHS (ID, ZT)values ('10102', '0');
- insert into TAB_FXHS (ID, ZT)values ('10103', '0');
- insert into TAB_FXHS (ID, ZT)values ('10121', '0');
- insert into TAB_FXHS (ID, ZT)values ('10121', '1');
- insert into TAB_FXHS (ID, ZT)values ('10121', '0');
- insert into TAB_FXHS (ID, ZT)values ('10121', '3');
- 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
- WITH ZT_PARTITION_BY_ID AS
- (SELECT ID, ZT, COUNT(ZT) OVER(PARTITION BY ID ORDER BY ID) ID_ZT
- FROM TAB_FXHS
- GROUP BY ID, ZT)
- SELECT *
- FROM ZT_PARTITION_BY_ID
- WHERE ID_ZT = 1
- 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!