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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:07:44+00:00 2026-06-09T18:07:44+00:00

First, I am sorry as I could not come up with better title for

  • 0

First, I am sorry as I could not come up with better title for this question.

I have a badge/achievement system in my website, community users are rewarded specific badges according to their activity in the website, below sql example I use to pull the number of users who made at at least 100 forum posts (I am using informix db version 10)

SELECT tjm.userid::INTEGER AS user_id, 
  EXTEND(DBINFO("UTC_TO_DATETIME",tjm.creationdate/1000), year to fraction) 
    AS earned_date
FROM TABLE(
  MULTISET(
    SELECT jm.userid, jm.creationdate, (
      SELECT COUNT(*) from TABLE(
        MULTISET(
          SELECT userid, creationdate
          FROM jive:jivemessage
        )
      ) AS i 
      WHERE i.userid = jm.userid AND i.creationdate < jm.creationdate
    ) + 1 AS row_num
    FROM jive:jivemessage jm 
  )
) AS tjm 
WHERE tjm.row_num=100

This sql takes around more than 30 minutes to execute, we have a very large community and there are millions of forum posts.

I would like to know if there is a solution to improve the query performance? I am trying to reduce the execution time because I have 40 sql queries similar to this one but for different tables and activities.

  • 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-06-09T18:07:45+00:00Added an answer on June 9, 2026 at 6:07 pm

    I don’t now Informix DB, but the query below should do what you ask and it’s ANSI SQL (except for the EXTEND part, which I copied from your original query).

    SELECT
      jm.userid
      ,EXTEND(DBINFO("UTC_TO_DATETIME",tjm.creationdate/1000), year to fraction) AS earned_date
    FROM
      (
      -- This sub-query will return all Users who have 100 messages or more
      SELECT
        jm.userid
        ,count(jm.userid) as totalmessages
      FROM
        jive:jivemessage jm
      GROUP BY
        jm.userid
      HAVING
        count(jm.userid) >= 100) AS MessageCount
    

    The above could probably be done without having to use a sub-query. The only reason why I used it is to have the DateEarned, as per original query, in the result set. Adding it to the sub-query would have required adding it to the GROUP BY, with unpredictable results if the query runs across two days (e.g. at 23:59:59).

    Update 2012/08/14 – Rewritten query following new requirements

    As I stated before, I don’t know Informix at all, therefore the following query may or may not run.

    SELECT
      UsersWithBadge.userid
      ,MAX(UsersWithBadge.creationdate) as dateearned
    FROM
      (
      SELECT FIRST 100
        jm.userid
        ,jm.creationdate
      FROM
        jive:jivemessage jm
        JOIN
        (-- This sub-query will return all Users who have 100 messages or more
        SELECT
          jm.userid
          ,count(jm.userid) as totalmessages
        FROM
          jive:jivemessage jm
        GROUP BY
          jm.userid
        HAVING
          count(jm.userid) >= 100)
        AS MessageCount ON
          (MessageCount.userid = jm.userid)
      ) AS UsersWithBadge     
    GROUP BY
      UsersWithBadge.userid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all sorry that I could not think of a more descriptive title.
First of all, I am sorry that this is not a 'question that can
Sorry about the rubbish question title. I have a table SET_DEFINITIONS like this: SETKEY
First of all, I'm sorry I can't figure out a better title for this
It's a badly worded title but I can't come up with anything better, sorry!
First off, sorry for the lame title, but I couldn't think of a better
First of all, I'm sorry about the feedback-nature of this question. I'm trying to
Sorry if this has been discussed somewhere else on stackoverflow (I could not find
first question here, this is regarding the iPhoneOS3 not MacOSX. I am fairly new
First of all, sorry to post a question like this when so many other

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.