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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:06:50+00:00 2026-06-01T05:06:50+00:00

Consider the following users table: uid followers following ff_fraction ————————————– 1 40 2 20

  • 0

Consider the following “users” table:

uid  followers  following  ff_fraction
--------------------------------------
1    40         2          20
2    10         3           3
3     0         2           0
4     5         0           5
5    77         2
6     9         3

I want to calculate, for each user, the fraction of followers/following, rounded to a whole number. I filled in the table for the first 4 users:

  1. 40/2 = 20
  2. 10/3 = 3.3333 => rounded 3
  3. 0/2 = 0
  4. 5/0 => this would give an error, so I counted +1, making 5/1 = 5

I now have the following query, but it does not account for “following” being zero (and that it thus would have to add 1 in order to not get a devision by zero error):

UPDATE users SET ff_fraction = ROUND(followers/following)

Is it possible to solve this in a MySQL query?

  • 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-01T05:06:51+00:00Added an answer on June 1, 2026 at 5:06 am

    You can do the following:

    UPDATE users SET ff_fraction = ROUND(followers/if(following>0,following,1))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following tables: users and tweets user_id name tweet_id user_id tweet spam -----------------
Consider the following table views user_id _date cnt ------------------------ 1 2011-02-10 123 1 2011-02-11
Consider the following tweets table tweet_id user_id text ----------------------------------------- 1 1 look at my
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
I am using Hibernate 4.1 and Spring 3.1. Consider the following User class having
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following example $q = Doctrine::getTable('User')->createQuery('u') ->where('u.username = ?', 'test'); If another related
Consider the following scenario We have a simple database that involves two entities: user
Consider the following use case 1. User selects a product to purchase on seller's
I have a relational record similar to the following: There are users (table users)

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.