2013-03-20 71 views
0

試圖找到一個公式,可以讓我顯示某些值。顯示多個值的公式

實施例:

我想看阿司匹林和華法林和(一個或多個接下來的3個值的)氯吡格雷或普拉格雷或替卡格雷。

Patient1需要:

阿司匹林 華法林 Clopidgrel

患者2花費: 阿司匹林 華法林

現在我看到兩個患者1和患者2,我只希望看到病人像患者1那樣顯示3種不同的藥物。

請幫助,並提前謝謝。我使用Crystal Reports 2008

+0

您是否在尋找一個**選擇**公式,使報告僅返回那些符合指定條件的病人?此外,您是否從關係數據源進行報告,如果有,是哪個RDBMS(SQLServer,Oracle,MySQL等)? (這種選擇可以在Crystal中完成,但在SQL中更容易並且可能更高效。) – 2013-03-20 13:17:44

+0

選擇公式,我們使用Oracle作爲數據源。 – user2169575 2013-03-20 13:19:12

+0

什麼是另一個不是SQL的公式。只是想能夠有選擇。 – user2169575 2013-03-20 13:55:53

回答

1

我建議添加類似以下行的SQL SELECT子句:

count(distinct case when medication in ('Aspirin', 'Warfarin') 
        then medication end) 
    over (partition by patient) as mandatory_meds, 
count(distinct case when medication in ('Clopidogrel', 'Prasugrel', 'Ticagrelor') 
        then medication end) 
    over (partition by patient) optional_meds, 

- 然後添加下列條件的SQL WHERE子句:

and mandatory_meds = 2 and optional_meds >= 1 


或者,您可以通過以下方式在水晶中實現類似結果:

  • 組由患者
  • 報告創建名爲mandatory_meds晶體式,用以下的公式:
    if {myTable.medication} = "Aspirin" or {myTable.medication} = "Warfarin"
    then {myTable.medication}
  • 創建晶體公式稱爲optional_meds狀態,用以下的公式:
    if {myTable.medication} = "Clopidogrel" or {myTable.medication} = "Prasugrel"
    or {myTable.medication} = "Ticagrelor" then {myTable.medication}
  • 組添加條件選擇公式,如:
    DistinctCount({@mandatory_meds})=2 and DistinctCount({@optional_meds})>=1