最小公约数
[摘要]一个朋友在展BOM的时候有这样的需求,两列字段(数值):A ,B A=用量,B=底数,组成用量=用量/底数。A/B,若能被整除,显示整除的结果,若不能整除显示分数形式A/B(分数形式要是约分后的格式)3/6=1/3。 我的思路: 1.SQL取余判断是否能被整除 2.撰
[摘要]一个朋友在展BOM的时候有这样的需求,两列字段(数值):A ,B A=用量,B=底数,组成用量=用量/底数。A/B,若能被整除,显示整除的结果,若不能整除显示分数形式A/B(分数形式要是约分后的格式)3/6=1/3。
我的思路:
1.SQL取余判断是否能被整除
2.撰写两个整形数值的最大公约数,然后分子与分母分别除以最大公约数。
其中进行转换化成字符串格式。
一、自定义最大公约数函数:
Create FUNCTION [dbo].[GetMaxgongyue] ( @num1 int , @num2 int ) RETURNS int as begin DECLARE @times INT DECLARE @min INT DECLARE @result BIGINT IF( @num1 >= @num2 ) SET @min=@num2 ELSE SET @min=@num1 SET @times=@min WHILE(@times <= @min ) BEGIN IF( @num1%@times = 0 AND @num2%@times = 0 ) BEGIN SET @result=@times BREAK END SET @times=@times - 1 END return @result end
drop table tt Create table tt(t1 int,t2 int) insert into tt(t1 ,t2 )values(1,3) insert into tt(t1 ,t2 )values(2,4) insert into tt(t1 ,t2 )values(3,9) insert into tt(t1 ,t2 )values(6,3) insert into tt(t1 ,t2 )values(4,2) insert into tt(t1 ,t2 )values(2,331) select t1,t2,t1%t2 取余, case when t1%t2<>0 and dbo.GetMaxgongyue(t1,t2)=1 then CAST(t1 as NCHAR(4))+'/'+ CAST(t2 as NCHAR(4)) when t1%t2<>0 and dbo.GetMaxgongyue(t1,t2)<>1 then CAST(t1/dbo.GetMaxgongyue(t1,t2) as NCHAR(4))+'/'+ CAST(t2/dbo.GetMaxgongyue(t1,t2) as NCHAR(4)) else cast(cast(t1/t2 as decimal(9,5)) as NCHAR(20)) end result from tt

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



As one of the most popular short video platforms in China, Douyin has attracted a large number of users and fans. On TikTok, we often hear about fans and friends, but do you know what the difference is between TikTok fans and friends? This question will be answered in detail below. 1. What is the difference between Douyin fans and friends? On TikTok, fans are people who are interested in your content and choose to follow you. They will interact with you through likes, comments, etc. to establish a virtual connection. Friends, on the other hand, are people who know each other in real life and have real social relationships with each other. On social platforms like Douyin, the methods and depth of interactions between fans and friends may vary, but they are all important elements in building and maintaining a social network. The number of fans refers to those who follow your account

I don’t want AI to destroy the board game market, but I do want to try a German-style board game designed by pure AI. Article/Lao Lu If you want to talk about what is the hottest thing after this year’s Spring Festival, it is undoubtedly the AI that is about to pass the Turing test. First there were the "amazing" AI drawings, and then there were the constantly surprising ChatGPT and NewBing, all of which are stimulating people's neurons and "warning" people about the future. For example, the various public relations drafts written by people using ChatGPT are completely comparable to those written by some public relations companies, and the effects of AI-drawn scenery paintings can meet various needs. Google has also begun to consider gradually reducing its recruitment needs for positions that can be replaced by AI. What also appeared at the same time was the worry of many people

With the rapid development of the Internet, programming languages are constantly evolving and updating. Among them, Go language, as an open source programming language, has attracted much attention in recent years. The Go language is designed to be simple, efficient, safe, and easy to develop and deploy. It has the characteristics of high concurrency, fast compilation and memory safety, making it widely used in fields such as web development, cloud computing and big data. However, there are currently different versions of the Go language available. When choosing a suitable Go language version, we need to consider both requirements and features. head

In the current wave of science and technology, computing power, as the core driving force for the development of cutting-edge technologies such as artificial intelligence and big data, has become increasingly important. As a domestic technology giant, Huawei’s self-developed computing power GPU has attracted much attention in the market. However, with the surge in demand, the supply of Huawei's computing GPUs has become stretched, and prices have also risen. According to sources, Huawei’s computing GPU shipments are expected to be approximately 100,000 pieces in 2023, and production capacity is expected to increase to hundreds of thousands of pieces in 2024. However, the number of orders received so far has reached millions of pieces, especially in January this year, the order volume reached hundreds of thousands. This shortage of supply has led to extended delivery times for Huawei's computing GPUs, and has also driven prices to continue to rise. from

Here we will see an interesting problem. We have an array 'a' containing N elements. We need to find an element x that minimizes the value of |a[0]-x|+|a[1]-x|+...+|a[n-1]-x|. Then we need to find the minimized sum. Suppose the array is: {1,3,9,6,3}, and now x is 3. So the sum is |1-3|+|3-3|+|9-3|+|6-3|+|3-3|=11. To solve this problem, we need to choose the median of the array as x. If the size of the array is even, there will be two median values. They are all the best choices for x. Algorithm minSum(arr,n)begin &

There are 5 DOM objects including "document", "element", "Node", "Event" and "Window"; 2. "window", "navigator", "location" and "history" and "screen" and other 5 BOM objects.

BOM and DOM are different in terms of role and function, relationship with JavaScript, interdependence, compatibility of different browsers, and security considerations. Detailed introduction: 1. Role and function. The main function of BOM is to operate the browser window. It provides direct access and control of the browser window. The main function of DOM is to convert the web document into an object tree, allowing developers to Use this object tree to obtain and modify the elements and content of the web page; 2. Relationship with JavaScript, etc.

As the competition in the smartphone market becomes increasingly fierce, consumers often consider many factors when choosing a new mobile phone, among which budget and demand are one of the two most important considerations. Among many mobile phone brands, iQOO, as an emerging brand that has attracted much attention, has launched a series of well-received products, among which iQOO Neo8 Pro and iQOO Neo9 have attracted much attention from consumers. So, considering the budget and needs, is it more suitable to choose iQOONeo8Pro or iQOONeo9?
