Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql calculate percentage

(round((CAST(numerator AS real) / denominator)*100,2)) as "percent"
Comment

sql percentage

SELECT CONCAT(ROUND(smallerNum*100/biggerNum, 2), '%') FROM table
Comment

calculate percentage in sql

SELECT SUM(MARKS)*100/COUNT(MARKS) FROM STUDENT_MARKS
Comment

sql server function to calculate a percentage

-- =============================================
-- Author:		Simphiwe Mabaso
-- Create date: 05 July 2022
-- Description:	When called this function returns a percentage
-- =============================================
ALTER   FUNCTION [dbo].[CalculatePercentage]
(
	@Value DECIMAL(18, 2),
	@Total DECIMAL(18, 2)
)
RETURNS INT
AS
BEGIN
	-- Declare the return variable here
	DECLARE @Percentage AS DECIMAL(18, 2);

	-- Add the T-SQL statements to compute the return value here
	SET @Percentage = @Value / @Total * 100;

	-- Return the result of the function
	RETURN @Percentage;
END

------------------------------------------------------
--Testing the function
DECLARE @Percent DECIMAL(18, 7),
		@PercentageInString NVARCHAR(50);

SET @Percent = dbo.CalculatePercentage(92, 45);

SET @PercentageInString = CONVERT(NVARCHAR(50), @Percent) + '%';

SELECT @PercentageInString  [Percentage];
Comment

PREVIOUS NEXT
Code Example
Sql :: sql change data type 
Sql :: sql insert column 
Sql :: mysql auerries to find the name starting with vowel letter 
Sql :: mysql drop key 
Sql :: set all auto_increment values in sql 
Sql :: mysql root permission denied lost 
Sql :: sqlserver add column 
Sql :: setting default value for Boolean data type in SQL 
Sql :: how to ascending order in sql 
Sql :: sql download for windows 10 
Sql :: sql view talbe columns 
Sql :: restore postgresql database from dump file 
Sql :: sql server list database 
Sql :: alter table primary key postgresql 
Sql :: postgres trigger insert into another table 
Sql :: mysql loop 
Sql :: mysql random 
Sql :: sql not equal 
Sql :: install mysql 5.7 ubuntu 20.04 
Sql :: create function in sql 
Sql :: select only one row sql 
Sql :: mysql on duplicate key update get value from values 
Sql :: default value false mysql 
Sql :: truncate psql 
Sql :: oracle list days between two dates 
Sql :: oracle ddl 
Sql :: update table sql multiple set 
Sql :: show function mysql 
Sql :: how covert into int in maria db 
Sql :: insert many to many sql 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =