select a.sumn, convert(numeric(50),cast(abs(a.sumn-b.bsum)/b.bsum as decimal(5,2))*100,120) as tb怎么写可以保证被除数bsum为0是不计算
时间: 2023-04-04 14:03:44 浏览: 51
可以使用CASE语句来判断bsum是否为0,如果为0则返回NULL,否则按照原式计算。具体代码如下:
SELECT a.sumn,
CASE
WHEN b.bsum = 0 THEN NULL
ELSE CONVERT(NUMERIC(50), CAST(ABS(a.sumn - b.bsum) / b.bsum AS DECIMAL(5, 2)) * 100, 120)
END AS tb
FROM table_a a
INNER JOIN table_b b
ON a.id = b.id
相关问题
bcell.getNumericCellValue() Cannot get a NUMERIC value from a STRING cell 如何解决
这个错误是因为你正在尝试从一个字符串类型的单元格获取数字值。要解决这个问题,你需要根据单元格的类型来选择正确的方法。
首先,你可以使用getCellType()方法来确定单元格的类型。如果单元格的类型是字符串类型(CellType.STRING),你可以使用getStringCellValue()方法来获取其值。如果单元格的类型是数字类型(CellType.NUMERIC),你可以使用getNumericCellValue()方法来获取其值。
下面是一个示例代码,展示了如何根据单元格的类型来获取值:
```java
Cell cell = row.getCell(columnIndex);
if (cell.getCellType() == CellType.STRING) {
String value = cell.getStringCellValue();
// 处理字符串类型的值
} else if (cell.getCellType() == CellType.NUMERIC) {
double value = cell.getNumericCellValue();
// 处理数字类型的值
}
```
// Add's the given number to the given date Value. // // Usage: // dateAdd(var,var,var); // 1: Date - The Variable with the Date. // 2: String - The Type which represents the value // to add. // y - Years // m - Months // d - Days // w - Weeks // wd - Workingdays // hh - Hours // mi - Minutes // ss - Seconds // 3: Numeric - The Value to add. // // 2006-11-15 // var d1 = new Date(); Alert(dateAdd(d1, "y", 1)); Alert(dateAdd(d1, "m", 4)); Alert(dateAdd(d1, "d", 5)); Alert(dateAdd(d1, "wd", 5));
在给定的代码中,`dateAdd()` 函数用于将给定的数值添加到给定的日期值上。以下是函数的使用方法和示例:
```javascript
// Add's the given number to the given date Value.
//
// Usage:
// dateAdd(var,var,var);
// 1: Date - The Variable with the Date.
// 2: String - The Type which represents the value to add.
// y - Years
// m - Months
// d - Days
// w - Weeks
// wd - Working days
// hh - Hours
// mi - Minutes
// ss - Seconds
// 3: Numeric - The Value to add.
//
// Example usage:
var d1 = new Date();
Alert(dateAdd(d1, "y", 1)); // Add 1 year to the date
Alert(dateAdd(d1, "m", 4)); // Add 4 months to the date
Alert(dateAdd(d1, "d", 5)); // Add 5 days to the date
Alert(dateAdd(d1, "wd", 5)); // Add 5 working days to the date
```
在上面的示例中,我们首先创建了一个 `Date` 对象 `d1`,表示当前日期和时间。然后,我们使用 `dateAdd()` 函数将指定的数值添加到 `d1` 中,并根据第二个参数指定的类型来确定要添加的时间单位。最后,我们使用 `Alert()` 函数来显示添加后的日期。
请注意,`dateAdd()` 函数在给定的代码中是自定义实现的,并不是 JavaScript 内置函数。如果要使用这个函数,请确保在代码中定义了 `dateAdd()` 函数的实现。