-1

"What is the total charged of the Item 307 and 413 to each patient who has had both items billed to their account? (use 'OR' or IN)". I have figured out how to sum the charges so that items 413 and 307 have been summed. The problem is patient 1837 and patient 3249 only have either item 413 or 307, they don't have both. I have tried using an "AND" statement to filter on both numbers but no rows are returned. How do I filter it for just patient #7325 and 6251? picture of my output shows my query, and what data comes out. I am hoping to have this same output but without the rows correlated with patient_no 1837 & 3249.

www20
  • 7
  • 3
  • 1
    Your query, sample data and desired results would all help the question. – Gordon Linoff Nov 07 '19 at 21:54
  • @GordonLinoff my query and sample data are in the picture that I attached! My desired result is what I have in the picture without the two rows correlated with patient_no 1837 & 3249. – www20 Nov 07 '19 at 21:56

1 Answers1

0

If you only requesting these two items, then you must have exactly two types of item_codes contributing to the aggregate. A having clause will address this.

having count(distinct item_code) = 2

Guarantees that you have two types of items contributing to this aggregate result.

Jeremy Fortune
  • 2,459
  • 1
  • 18
  • 21