SQL joining question

后端 未结 3 1891
庸人自扰
庸人自扰 2020-12-21 08:28

Here is my situation:

I have one table that contains a list of drugs sold containing the NDC (an identifier), quantity sold, and whether the drug is a brand name or

3条回答
  •  难免孤独
    2020-12-21 09:02

    This would get you each one on a separate line:

    SELECT
      `cl`.`ndc`,
      `cl`.`rx_num`
    FROM `claims_list` AS `cl`
    WHERE `cl`.`ndc` IN
      (
        SELECT `dl`.`ndc` FROM `drug_list` AS `dl`
        WHERE `dl`.`type` = 'Generic'
        ORDER BY `dl`.`qty` DESC
        LIMIT 50
      )
    ORDER BY `cl`.`date` DESC
    LIMIT 4
    

    Then run the results through a filter in the calling script to group them together.

提交回复
热议问题