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 7415209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:15:21+00:00 2026-05-29T07:15:21+00:00

I have a table with app statistics, let’s say the columns are os_version and

  • 0

I have a table with app statistics, let’s say the columns are os_version and app_id (simplifying). I want to list all OS versions for a certain app, and for each OS version I want to see a number of records that have at least this OS version. Example data:

app1 1.0
app1 2.0
app2 1.0

Now for app1 I want to see:

version | score | comments
--------+-------+---------
1.0     | 2     | there are two records having OS at least 1.0
2.0     | 1     | there is just one record with OS at least 2.0

Now, pardon my ignorant SQL, but I have come up with this query:

SELECT
    os_version,
    -- number_of_records_having_at_least_this_version / number_of_all_records
    (SELECT COUNT(*) FROM stats WHERE app_id='app1' AND os_version >= outer.os_version)/ 
        (SELECT COUNT(*) FROM stats WHERE app_id='app1') AS score
FROM (SELECT * FROM stats WHERE app_id='app1') AS outer
GROUP BY os_version;

This is crazy, as I have to filter by the app ID three times. Is it possible to filter by the app ID first and then use the resulting row set for further operations? Without a temporary table? In SQLite? Something like:

SELECT
    os_version,
    (SELECT COUNT(*) FROM filtered WHERE os_version >= filtered.os_version)/
        (SELECT COUNT(*) FROM filtered) AS score
FROM (SELECT * FROM stats WHERE app_id='app1') AS filtered
GROUP BY os_version;

…which, sadly, does not work.

  • 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-29T07:15:23+00:00Added an answer on May 29, 2026 at 7:15 am

    I think, if I’ve understood the question properly, that something like this should do the trick..

    SELECT
        s1.app_id,
        s1.os_version,
        count(*)
    FROM stats s1 INNER JOIN stats s2 ON s1.app_id = s2.app_id 
                                      AND s2.os_version >= s1.os_version
    GROUP BY s1.app_id, s1.os_version
    

    EDIT: This returns results fitered by app_id (as with the example query in the question)

    SELECT
        s1.app_id,
        s1.os_version,
        count(*)
    FROM stats s1 INNER JOIN stats s2 ON s1.app_id = s2.app_id 
                                      AND s2.os_version >= s1.os_version
    WHERE s1.app_id = 'app1'
    GROUP BY s1.app_id, s1.os_version
    

    EDIT2:

    SELECT
        s1.app_id,
        s1.os_version,
        count(*)
    FROM stats s1 INNER JOIN stats s2 ON s1.app_id = s2.app_id 
                                      AND s2.os_version >= s1.os_version
                                      AND s1.app_id = 'app1'
    GROUP BY s1.app_id, s1.os_version
    

    EDIT3: To get round the 2.11 < 2.7 problem

    SELECT
        s1.app_id,
        s1.os_version,
        count(*)
    FROM stats s1 INNER JOIN stats s2 ON s1.app_id = s2.app_id 
                  AND CAST(REPLACE(s2.os_version, '.', '') TO INTEGER) >= 
                      CAST(REPLACE(s1.os_version, '.', '') TO INTEGER)
                  AND s1.app_id = 'app1'
    GROUP BY s1.app_id, s1.os_version
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an app where I have a table view and when
Let's say I have a rails app with 3 tables, one for questions, one
I am developing an app in which I have a table. In the table
I'm using Google App Engine and Django templates. I have a table that I
I have a simple cakephp app with table articles that has a cat_id column
I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines
In my Ruby on Rails app, I have a User table and a Foo
I have an app that needs to check a database table every minute. The
I have this .NET web app that draws a table in Page_Load. Then after
I have a small app/site on a dev server with a data table in

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.