Home > database >  Orcal statement query
Orcal statement query

Time:09-27

 select * 
The from (select rt objid,
Rt. The title,
SFD forcastvalue,
SFD indicatorcode,
Rt ratingvalue,
To_char (SFD) forcasttime, 'yyyy) baseyear,
(case SFD. Indicatorcode
When the '0011' then
SFD. Forcastvalue
The else
'
End) price,
(case SFD. Indicatorcode
When the '0004' then
SFD. Forcastvalue
The else
'
End) eps
The from ir_report rt
Left the join sr_stockforecastrelation SFR on SFR. Sourceentity=
Rt. Entityname
And SFR) sourceid=rt) objid
Left the join sr_stockforecastdetail SFD on SFD. Forecastid=
SFR. Forecastid

Where rt. Objid=3111
And SFD. Indicatorcode in (0004, 0011)
The order by SFD. Forcasttime)

Perform
Objid title code ravalue year price eps
D 0004 50, 2016, 1 3111, flags, drum 1.40
2, 3111, zero flag drum D 0011, 50, 2017 52
3, 3111, zero flag drum D 0004, 50, 2017 1.00
I want the effect of
Objid title code (can be removed) ravalue year price eps
0004/0011 3111, zero flag drum, 1 D (can be removed) 50 2017 52 1.00
Is according to the maximum of objid and year to merge a line, strives for the great god modify!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

The
refer to the original poster QKLNMC response:
 select * 
The from (select rt objid,
Rt. The title,
SFD forcastvalue,
SFD indicatorcode,
Rt ratingvalue,
To_char (SFD) forcasttime, 'yyyy) baseyear,
(case SFD. Indicatorcode
When the '0011' then
SFD. Forcastvalue
The else
'
End) price,
(case SFD. Indicatorcode
When the '0004' then
SFD. Forcastvalue
The else
'
End) eps
The from ir_report rt
Left the join sr_stockforecastrelation SFR on SFR. Sourceentity=
Rt. Entityname
And SFR) sourceid=rt) objid
Left the join sr_stockforecastdetail SFD on SFD. Forecastid=
SFR. Forecastid

Where rt. Objid=3111
And SFD. Indicatorcode in (0004, 0011)
The order by SFD. Forcasttime)

Perform
Objid title code ravalue year price eps
D 0004 50, 2016, 1 3111, flags, drum 1.40
2, 3111, zero flag drum D 0011, 50, 2017 52
3, 3111, zero flag drum D 0004, 50, 2017 1.00
I want the effect of
Objid title code (can be removed) ravalue year price eps
0004/0011 3111, zero flag drum, 1 D (can be removed) 50 2017 52 1.00
Is according to the maximum of objid and year to merge a line, strives for the great god modify!!!!!!!!!!!!!!!!!!!!!!!!!!!!



If you can remove the field code, you can according to objid and grouping title take Max (year), Max (NVL (price, 0)), min (NVL (eps, 999999).

CodePudding user response:

 
Select objid, title, forcastvalue indicatorcode, ratingvalue, baseyear, Max (price) price, Max (eps) eps
The from (select rt objid,
Rt. The title,
SFD forcastvalue,
SFD indicatorcode,
Rt ratingvalue,
To_char (SFD) forcasttime, 'yyyy) baseyear,
(case SFD. Indicatorcode
When the '0011' then
SFD. Forcastvalue
The else
'
End) price,
(case SFD. Indicatorcode
When the '0004' then
SFD. Forcastvalue
The else
'
End) eps,
Rank () over (partition by rt. Objid order by to_char (SFD) forcasttime, 'yyyy) desc) rn
The from ir_report rt
Left the join sr_stockforecastrelation SFR on SFR. Sourceentity=
Rt. Entityname
And SFR) sourceid=rt) objid
Left the join sr_stockforecastdetail SFD on SFD. Forecastid=
SFR. Forecastid

Where rt. Objid=3111
And SFD. Indicatorcode in (0004, 0011)
The order by SFD. Forcasttime)
Where an rn=1
Group by objid, title, forcastvalue indicatorcode, ratingvalue, baseyear


Haven't tested, the original poster can try and see

CodePudding user response:

refer to the second floor l3751202 response:
 
Select objid, title, forcastvalue indicatorcode, ratingvalue, baseyear, Max (price) price, Max (eps) eps
The from (select rt objid,
Rt. The title,
SFD forcastvalue,
SFD indicatorcode,
Rt ratingvalue,
To_char (SFD) forcasttime, 'yyyy) baseyear,
(case SFD. Indicatorcode
When the '0011' then
SFD. Forcastvalue
The else
'
End) price,
(case SFD. Indicatorcode
When the '0004' then
SFD. Forcastvalue
The else
'
End) eps,
Rank () over (partition by rt. Objid order by to_char (SFD) forcasttime, 'yyyy) desc) rn
The from ir_report rt
Left the join sr_stockforecastrelation SFR on SFR. Sourceentity=
Rt. Entityname
And SFR) sourceid=rt) objid
Left the join sr_stockforecastdetail SFD on SFD. Forecastid=
SFR. Forecastid

Where rt. Objid=3111
nullnullnullnullnullnullnullnullnull
  • Related