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 :: how to drop all tables in sql 
Sql :: sql calculate working days between two dates excluding weekends and holidays 
Sql :: mysql ip address data type 
Sql :: search mysql database for column 
Sql :: sql views 
Sql :: mysql full outer join 
Sql :: mysql alter add foreign key 
Sql :: mysql list tables by size 
Sql :: events mysql 
Sql :: sql count number of rows after group by 
Sql :: postgres list users and roles 
Sql :: how to select unique element in sql 
Sql :: sql check duplicate value in column 
Sql :: mysql two column combination unique 
Sql :: sql insert from excel 
Sql :: get records in sql according to month name and count 
Sql :: how to select distinct in mysql 
Sql :: mysql select default if null 
Sql :: output table plsql 
Sql :: sql server insert into table 
Sql :: if in mysql 
Sql :: MySQL INSERT IGNORE Statement 
Sql :: alter table add check constraint oracle 
Sql :: sql constraint check value in list 
Sql :: sql character index 
Sql :: select top 3 sql 
Sql :: display all node label neo4j 
Sql :: mysql root permission denied lost 
Sql :: insert into values select 
Sql :: restore postgresql database from dump file 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =