I have tables like this:
TABLE 1 - PERSON:
m_id | name |
-------------
22 | jo |
-------------
77 | john |
--------------
TABLE 2 - AMT_DATA
m_id | amt | activity |
-------------------------
22 | 100 | - |
-------------------------
77 | 300 | n |
-------------------------
TABLE 3 - STATUS_DATA:
m_id | status | s_date |
22 | first | 01.01.2000 |
22 | second | 01.01.2001 |
22 | third | 01.01.2002 |
77 | first | 01.01.2001 |
77 | third | 01.01.2002 |
For one m_id there can be more rows in table STATUS_DATA.
I have this select but it will return multiple rows for one m_id.
SELECT PERSON.M_ID, PERSON.NAME, AMT_DATA.AMT, AMT_DATA.ACTIVITY, STATUS_DATA.STATUS, STATUS_DATA.S_DATE FROM PERSON
INNER JOIN AMT_DATA.M_ID ON AMT_DATA.M_ID = PERSON.M_ID
INNER JOIN STATUS_DATA.M_ID ON STATUS_DATA.M_ID = PERSON.M_ID
WHERE (AMT_DATA.ACTIVITY = '-');
Can i somehow get result for one m_id in one row? Like this:
person_id | person_name | amt_data.amt | amt_data.activity | status_data.status1 | status_data.s_date1 | .... |status_data.statusN | status_data.s_dateN
Thank you
A stored function, which returns
SYS_REFCURSOR
type variable, can be created in order to produce the sql statement that includes conditional aggregation such asand then call by using
from SQL developer's console to produce columns dynamically depending on the
status
ands_date
values varying throughout the rows.