Home > database >  Oracle query statement
Oracle query statement

Time:09-24

There are customer account opening information table, table structure is as follows:
Customer account name to open an account date
10321165 piece 20000123
10330256 2 20000125
... ... ...
10340025 zhang 20011201
10340252 zhang four 20011202
10340252 5 20011203
... ... ...
10350625 pieces of six 20171222
10350626 seven 20171223
... ... ...


Above the table: the customer account only, opening date is not the only, now out such as: zhang SAN's opening date is: 20011201, please back since 20011201 to 20171231 in this table there are many different days (because of some natural day there is no account records in the table),
To the results of the structure is as follows:
Customer accounts, customer name, date of account opening, open an account in the date in the future days different
in the table

CodePudding user response:

Customer account fid
Customer name fname
Opening date fdate
The select t.f id,
T.f name,
To_char (t.f date, 'YYYYMMDD') as fd,

(select count (distinct to_char (a.f date, 'YYYYMMDD'))
The from table1 a
Where a.f date & gt; T.f date) as ts
The from table1 t
The order by t.f date;
Thus,
For your reference ~ ~ ~

CodePudding user response:

Have to open an account record and not to open an account to how to distinguish

CodePudding user response:

Look from the demand of the literal, count (distinct)

CodePudding user response:

Customer account group not only needed?

CodePudding user response:

The select a. ank_no,
A.u ser_name,
Min (a.k h_date) as kh_date,
Count (distinct (case when a.r n> 1 then the date else 'end) as gs_date
The from
(select bank_no,
User_name,
Min (to_char (date, 'yyyy - mm - dd)) over (partition by bank_no) as kh_date,
Row_number () over (partition by bank_no order by date) rn
From the table) a
Group by a. ank_no,
A.u ser_name
  • Related