PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] how to show decimals in sql instead of 0

 August 11, 2022     decimal, mysql, sql     No comments   

Issue

I am trying to get the percent and it just shows up as zero. I want to show two decimal places such as 0.65 Here is a piece of the query I am selecting:

select count(numbers)/count(othernumbers) decimal(3,2) as"rate"

if I use this it shows up as 0 and gets rid of the rest

select count(numbers)/count(othernumbers) as"rate"

Solution

SELECT FORMAT(this / that, 2) as rate

Meanwhile, I question whether COUNT(numbers) is what you want. That counts how many rows have a non-NULL value in the column numbers.

Also, fraction is usually more like x / (x+y) -- meaning the fraction of the total (x+y) that is x.

A "percentage" needs 100* somewhere. 13/20 is the fraction 0.65 or the percentage 65.00 .



Answered By - Rick James
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing