How to select patients with two specific items charged to them? [duplicate]

29
November 08, 2019, at 2:40 PM

This question already has an answer here:

  • SELECTING with multiple WHERE conditions on same column 12 answers

I am working on a mini case for an MIS class and one of the questions asks "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.

Answer 1

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.

READ ALSO
how to insert python in to mysql

how to insert python in to mysql

I am writing an insert statement for python to add data to a mysql database and I am getting an error

18
Python mysql-connector SELECT in loop returns outdated result

Python mysql-connector SELECT in loop returns outdated result

I'm using mysql-connector to run a SELECT query in a while loop to look for new jobs

18
What is the fastest way to implementing algorithm to manipulate and insert sql records?

What is the fastest way to implementing algorithm to manipulate and insert sql records?

I have a table named as TRENDS, containing around 20k recordsI need to manipulate each row of TRENDS table based on the each column value and final output of the row is a string, named insight which is nothing but that manipulated row

25
Speed up group by

Speed up group by

Consider the following query:

44