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

  • SEARCH
  • Home
  • 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 6366241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:23:47+00:00 2026-05-25T00:23:47+00:00

I have a table which holds the data of many seq_id. Each seq_id has

  • 0

I have a table which holds the data of many seq_id. Each seq_id has many hits (hit_name_id) on different rows. What I want to do is group the seqs into groups if their hits are similar (ie share around 70-80% of hits) Eg in the table below sequences 1,2 and 4 are actually very similar so that more than likely they are the same thing. I want to be able to assign all the similar hits with a group id so that I can later extract just the unique seqs.

I created this query to demonstrate that each seq_id can have many hits that may or may not be shared:

mysql> SELECT seq_id,GROUP_CONCAT(hit_name_id ORDER BY hit_name_id), count(hit_name_id) FROM polished_data
    -> GROUP BY seq_id;
+--------+------------------------------------------------+--------------------+
| seq_id | GROUP_CONCAT(hit_name_id ORDER BY hit_name_id) | count(hit_name_id) |
+--------+------------------------------------------------+--------------------+
|      1 | 4,5,6,9,10,14,19,20,21                         |                  9 |
|      2 | 4,6,9,10,14,18,19,20,21                        |                  9 |
|      3 | 6,12,13,14,18,20                               |                  6 |
|      4 | 4,7,8,11,14,18,19,20,21                        |                  9 |
|      5 | 1,2,3,15,16,17,32                              |                  7 |
+--------+------------------------------------------------+--------------------+

I am not sure whether I can accomplish this in MySQL or whether I will need to program this step in my linked program.

  • 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-25T00:23:47+00:00Added an answer on May 25, 2026 at 12:23 am

    This will count the number of hits that are same.

    SELECT seq_id, COUNT(*) AS same
    FROM polished_data
    WHERE 
        hit_name_id IN (SELECT hit_name_id FROM polished WHERE seq_id = ###) 
        AND and seq_id != ### 
    GROUP BY seq_id
    

    You can then extend this and calculate how many are different (it appears in either but not both), then join them together.

    SELECT *, (same/(same+diff)) AS similarity   
    FROM
    (
        SELECT 
            s.seq_id, 
            s.same,
            ((t.total-s.same)+(ct.total-s.same)) AS diff 
    
        FROM 
    
            (SELECT seq_id, COUNT(*) as total FROM polished_data
             GROUP BY seq_id) AS t  
    
        LEFT JOIN
    
            (SELECT seq_id, COUNT(*) AS same
             FROM polished_data
             WHERE 
                 hit_name_id IN 
                     (SELECT hit_name_id FROM polished_data 
                      WHERE seq_id = ###) 
             GROUP BY seq_id) AS s
    
        ON t.seq_id = s.seq_id
    
        JOIN
    
            (SELECT COUNT(*) as total FROM polished_data
             WHERE seq_id = ###) AS ct  
    
    ) as result   
    

    Using random data you get something like this (tested using ### replaced by 1).

    +--------+------+------+------------+
    | seq_id | same | diff | similarity |
    +--------+------+------+------------+
    |      1 |   22 |    0 |     1.0000 |
    |      2 |    4 |   45 |     0.0816 |
    |      3 |    5 |   57 |     0.0806 |
    |      4 |    8 |   34 |     0.1905 |
    |      5 |    9 |   47 |     0.1607 |
    |      6 |    3 |   36 |     0.0769 |
    |      7 |    7 |   45 |     0.1346 |
    |      8 |    3 |   48 |     0.0588 |
    |      9 |    9 |   46 |     0.1636 |
    |     10 |    4 |   48 |     0.0769 |
    +--------+------+------+------------+
    

    Change the ### in the above SQL to be the seq_id you want to compare against.

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

Sidebar

Related Questions

I have a myism table 'test' which holds some out-dated data, now I want
I have a table which holds flight schedule data. Every schedule have an effective_from
I have a games table which holds the data about a game. Then another
I have the following table which holds data on customers and staff. Would it
I have a main MySQL table which holds products. Any multiple fields for each
I have a table, which holds (besides all other data) information, when this data
I have a database table which holds meta data about images, the field in
I have one table in my core data source which holds some articles with
If you have a table which holds history (updates, deletes) from another table, how
I have a parent table called 'Website' which holds records about websites. I have

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.