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 :: psql view databases 
Sql :: update a column with another column in same table mysql 
Sql :: how to add multiple column in mysql 
Sql :: oracle procedure teamplate 
Sql :: sql less than operator 
Sql :: sql is not null 
Sql :: auto increment psql not primary key 
Sql :: like operator in sql 
Sql :: les jointures sql server 
Sql :: update view sql 
Sql :: sql query interview questions githu 
Sql :: sql file in postgres with pgadmin 
Sql :: how to generate er diagram in mysql workbench 
Sql :: sqlite3.OperationalError: near "WHERE": syntax error 
Sql :: convert sql to linq c# online 
Sql :: insert overwrite table in mysql in nifi 
Sql :: TITLE: SQL Server principal "dbo" does not exist 
Sql :: oracle change password expiration policy 
Sql :: Insert into Select * - NAYCode.com 
Sql :: mysql config address 
Sql :: reorder primary key sql 
Sql :: create sql table from script inline primary key constraint 
Sql :: oracle allow space to user 
Sql :: ring MySQL create new table and insert records 
Sql :: second highest salary in mysql 
Sql :: acceso denegado en msql 
Sql :: how to know which table has more data oracle sql 
Sql :: BigQuery: join 2 tables but only choosing rows based on date column 
Sql :: mamp mysql config file 
Sql :: compute age mysql 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =