For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Hi,
Thanks for posting the sampled data.
Don't forget to post the exact results you want from that data.
Are these the results you want?
R_NUM FRI_S FRI_H MON_S MON_H THU_S THU_H ----- ----- -------------- ----- -------------- ----- -------------- 1 08:54 SEYMA DURLANIK 13:00 SEYHAN UNVER 08:30 ZUHRE YEL 2 10:00 SENGUL AKBAS 13:30 SELMA CALISKAN 08:48 AYSEL POLAT 3 13:30 ORHAN SAVAS 17:45 ESMA COMERT 4 14:00 FATMA ETA
R_NUM FRI_S FRI_H MON_S MON_H THU_S THU_H
----- ----- -------------- ----- -------------- ----- --------------
1 08:54 SEYMA DURLANIK 13:00 SEYHAN UNVER 08:30 ZUHRE YEL
2 10:00 SENGUL AKBAS 13:30 SELMA CALISKAN 08:48 AYSEL POLAT
3 13:30 ORHAN SAVAS 17:45 ESMA COMERT
4 14:00 FATMA ETA
(I only included 3 days of the week, just to save space.)
Here's one way to get them:
WITH got_r_num AS ( SELECT TO_CHAR (t.r_tarihi, 'DY') AS gun , TO_CHAR (t.baslama, 'HH24:MI') AS saat , h.adi || ' ' || h.soyadi AS hasta , ROW_NUMBER () OVER ( PARTITION BY TO_CHAR (t.r_tarihi, 'DY') ORDER BY t.baslama ) AS r_num FROM randevu_entegre_deneme t LEFT OUTER JOIN hasta_deneme h ON h.id = t.hasta_id WHERE r_tarihi BETWEEN TO_DATE ('20.5.2011', 'dd.mm.yyyy') AND TO_DATE ('20.5.2011', 'dd.mm.yyyy') + 9 -- AND TO_CHAR (R_TARIHI, 'DY') NOT IN ('CMT','PAZ') ) SELECT * FROM got_r_num PIVOT ( MIN (SAAT) AS s , MIN (HASTA) AS h FOR gun IN ( 'FRI' AS fri -- , 'SAT' AS sat , 'MON' AS mon , 'THU' AS thu ) ) ORDER BY r_num ;
WITH got_r_num AS
(
SELECT TO_CHAR (t.r_tarihi, 'DY') AS gun
, TO_CHAR (t.baslama, 'HH24:MI') AS saat
, h.adi || ' ' || h.soyadi AS hasta
, ROW_NUMBER () OVER ( PARTITION BY TO_CHAR (t.r_tarihi, 'DY')
ORDER BY t.baslama
) AS r_num
FROM randevu_entegre_deneme t
LEFT OUTER JOIN hasta_deneme h ON h.id = t.hasta_id
WHERE r_tarihi BETWEEN TO_DATE ('20.5.2011', 'dd.mm.yyyy')
AND TO_DATE ('20.5.2011', 'dd.mm.yyyy') + 9
-- AND TO_CHAR (R_TARIHI, 'DY') NOT IN ('CMT','PAZ')
)
SELECT *
FROM got_r_num
PIVOT ( MIN (SAAT) AS s
, MIN (HASTA) AS h
FOR gun IN ( 'FRI' AS fri
-- , 'SAT' AS sat
, 'MON' AS mon
, 'THU' AS thu
ORDER BY r_num
;
I used the English names for the days, because this site thinks that the abbreviation for "Cuma" is a naughty word, and won't allow me to post it.
thank you for your attention. I get ora-00933 in,
SELECT TO_CHAR (t.r_tarihi, 'DAY') AS gun
, ROW_NUMBER () OVER ( PARTITION BY TO_CHAR (t.r_tarihi, 'DAY')
PIVOT ((here)) ( MIN (SAAT) AS s
FOR gun IN ( 'CUMA' AS fri
, 'PAZARTESI' AS mon
, 'PERSEMBE' AS thu
44e4386e-32a5-44eb-a5f5-d8a088ed0bd9 wrote: Hi, I want to exact results form:
44e4386e-32a5-44eb-a5f5-d8a088ed0bd9 wrote:
I want to exact results form:
thanks for your attention.
I don't see how you get those results from the given sample data. For example, I don't see 'ISMAHAN' anywhere in the data; how do you get 'ISMAHAN' in the results?
no I haven't got this result.
I prepare in excel this results. this records from real table.
I had prepared before writing statements.
44e4386e-32a5-44eb-a5f5-d8a088ed0bd9 wrote: no I haven't got this result. I prepare in excel this results. this records from real table. I had prepared before writing statements.
Kardeşim sen ne yapmak istiyosun söyle yardımcı olayım? Hemşerimi görmüşüm bırakmam
Translate: I am just asking him what he exactly wants to do?
Thank you very much Frank.
I try on my friends computer when it's done. He using oracle 12 c version.
How can I merge this column
İstediğin kod aşağıdaki gibidir. (Here is the code that you want)
SELECT * FROM ( select TRIM(TO_CHAR(R_TARIHI, 'DAY')) as gun, TO_CHAR(T.BASLAMA,'HH24:MI') AS SAAT,(h.adi || ' ' ||h.soyadi) as hasta from RANDEVU_ENTEGRE_DENEME t left outer join hasta_DENEME h on h.id=t.hasta_id where R_TARIHI between to_Date('20.5.2011','dd.MM.yyyy') and (to_Date('20.5.2011','dd.MM.yyyy')+9) ) PIVOT ( listagg(hasta) within group(order by hasta) FOR (gun) in ('PAZARTESI', 'SALI', 'CARSAMBA', 'PERSEMBE', 'CUMA') );
SELECT * FROM (
select TRIM(TO_CHAR(R_TARIHI, 'DAY')) as gun, TO_CHAR(T.BASLAMA,'HH24:MI') AS SAAT,(h.adi || ' ' ||h.soyadi) as hasta
from RANDEVU_ENTEGRE_DENEME t left outer join hasta_DENEME h on h.id=t.hasta_id
where R_TARIHI between to_Date('20.5.2011','dd.MM.yyyy') and (to_Date('20.5.2011','dd.MM.yyyy')+9)
) PIVOT (
listagg(hasta) within group(order by hasta) FOR (gun) in ('PAZARTESI', 'SALI', 'CARSAMBA', 'PERSEMBE', 'CUMA')
);
Eğer günler ingilizce ise aşağıdaki gibi olması lazım.
SELECT * FROM ( select TRIM(TO_CHAR(R_TARIHI, 'DAY')) as gun, TO_CHAR(T.BASLAMA,'HH24:MI') AS SAAT,(h.adi || ' ' ||h.soyadi) as hasta from RANDEVU_ENTEGRE_DENEME t left outer join hasta_DENEME h on h.id=t.hasta_id where R_TARIHI between to_Date('20.5.2011','dd.MM.yyyy') and (to_Date('20.5.2011','dd.MM.yyyy')+9) ) PIVOT ( listagg(hasta) within group(order by hasta) FOR (gun) in ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY') );
listagg(hasta) within group(order by hasta) FOR (gun) in ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY')
Kolay gelsin
Regards
44e4386e-32a5-44eb-a5f5-d8a088ed0bd9 wrote: kardeşim valla ne deyim allah razı olsun elimde yapmam gereken bir randevu tablosu var. bunları transpoze etmem gerekiyor. sorguyu bir türlü beceremedim. sağolsun Frank çok yardımcı olmaya çalıştı. fakat ora-00933 hatası alıyorum onun yazdığı sorguyla. nasıl çözebilirim ?
kardeşim valla ne deyim allah razı olsun
elimde yapmam gereken bir randevu tablosu var. bunları transpoze etmem gerekiyor.
sorguyu bir türlü beceremedim. sağolsun Frank çok yardımcı olmaya çalıştı. fakat ora-00933 hatası alıyorum onun yazdığı sorguyla.
nasıl çözebilirim ?
Bilader, Frank'in yazdığı kod doğru çalışıyor, eksik olan şey sende günler türkçe tanımlı onda ingilizce dolayısıyla hata alıyorsun. Kırmızıyla boyadığım kısımları düzelteceksin, sorun bu.
Translate: I have just said that Frank's code is working correct. The problem is if you use SQL Developer the days are describe in Turkish. Therefore you have to change the red lines.
SELECT TRIM(TO_CHAR (t.r_tarihi, 'DAY')) AS gun
FOR gun IN ( 'PAZARTESI'
-- , 'SALI'
, 'CARSAMBA'
, 'PERSEMBE'
, 'CUMA')