Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 923735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:14:19+00:00 2026-05-15T19:14:19+00:00

I’m trying to find all coverage_set_id with more than one benefit_id attached summary_attribute (value=2004687).

  • 0

I’m trying to find all coverage_set_id with more than one benefit_id attached summary_attribute (value=2004687).

The query seems to be working fine without the GROUP BY & HAVING parts, but once I add those lines in (for the COUNT) my results are incorrect. Just trying to get duplicate coverage_set_id.

Pass-Through query via OBDC database:

SELECT DISTINCT
    b.coverage_set_id,
    COUNT (b.coverage_set_id) AS "COUNT"

FROM
    coverage_set_detail_view a
    JOIN contracts_by_sub_group_view b ON b.coverage_set_id = a.coverage_set_id
    JOIN request c ON c.request_id = b.request_id

WHERE
    b.valid_from_date BETWEEN to_date('10/01/2010','mm/dd/yyyy')
    AND to_date('12/01/2010','mm/dd/yyyy')
    AND c.request_status = 1463
    AND summary_attribute = 2004687
    AND benefit_id <> 1092333

GROUP BY
    b.coverage_set_id

HAVING
    COUNT (b.coverage_set_id) > 1

My results look like this:

-----------------------
COVERAGE_SET_ID | COUNT
-----------------------
4193706         | 8
4197052         | 8
4193926         | 112
4197078         | 96
4174168         | 8

I’m expecting all the COUNTs to be 2.


::EDIT::

Solution:

SELECT
c.coverage_set_id AS "COVERAGE SET ID",
c1.description AS "Summary Attribute",
count(d.benefit_id) AS "COUNT"

FROM (
SELECT DISTINCT coverage_set_id

FROM contracts_by_sub_group_view

WHERE
    valid_from_date BETWEEN '01-OCT-2010' AND '01-DEC-2010'
    AND request_id IN (
        SELECT request_id
        FROM  request
        WHERE request_status = 1463)
) a

JOIN coverage_set_master e ON e.coverage_set_id = a.coverage_set_id
JOIN coverage_set_detail c ON c.coverage_set_id = a.coverage_set_id
JOIN benefit_summary d ON d.benefit_id = c.benefit_id
 AND d.coverage_type = e.coverage_type
JOIN codes c1 ON c1.code_id = d.summary_attribute

WHERE
d.summary_attribute IN (2004687, 2004688)
AND summary_structure = 1000217

GROUP BY c.coverage_set_id, c1.description

HAVING COUNT(d.benefit_id) > 1

ORDER BY c.coverage_set_id, c1.description

And these were the results:

COVERAGE SET ID  |  SUMMARY ATTRIBUTE  |  COUNT
-------------------------------------------------
4174168          |  INPATIENT          |   2
4174172          |  INPATIENT          |   2
4191828          |  INPATIENT          |   2
4191832          |  INPATIENT          |   2
4191833          |  INPATIENT          |   2
4191834          |  INPATIENT          |   2
4191838          |  INPATIENT          |   2
4191842          |  INPATIENT          |   2
4191843          |  INPATIENT          |   2
4191843          |  OUTPATIENT         |   2
4191844          |  INPATIENT          |   2
4191844          |  OUTPATIENT         |   2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:14:20+00:00Added an answer on May 15, 2026 at 7:14 pm

    The coverage_set_id in both the HAVING and count part of the SELECT should be benefit_id.

    Since benefit_id is also in table a you can do the following

    SELECT  
        a.coverage_set_id,  
        COUNT (a.benefit_id) AS "COUNT"  
    
    FROM  
        coverage_set_detail_view a  
    
    WHERE  
        a.coverage_set_id in (
            SELECT b.coverage_set_id 
            FROM contracts_by_sub_group_view b
            WHERE b.valid_from_date BETWEEN to_date('10/01/2010','mm/dd/yyyy') AND to_date('12/01/2010','mm/dd/yyyy'))
        AND a.coverage_set_id in (
            SELECT b2.coverage_set_id
            FROM contracts_by_sub_group_view b2
            INNER JOIN request c on c.request_id=b2.request_id
            WHERE c.request_status = 1463)
        AND ?.summary_attribute = 2004687  
        AND a.benefit_id <> 1092333  
    
    GROUP BY  
        a.coverage_set_id  
    
    HAVING  
        COUNT (a.benefit_id) > 1  
    

    This removes the JOIN magnification that was occurring on the FROM since those tables are not needed to pull coverage_set_id and benefit_id. The only remaining need for the other 2 tables is to filter out data based on criteria, which is in the WHERE clause.

    I’m not sure what table summary_attribute lives in but it would follow a similar pattern to valid_from_date, request_status, or benefit_id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.