verifyCompetAmount 、verCompetAm02 、verCompetAm03三个字段任一相同则输出一致,怎么写
时间: 2024-12-17 15:56:09 浏览: 8
如果你想要找到verifyCompetAmount、verCompetAm02和verCompetAm03这三个字段中只要有任一两个字段值相同,则认为是一致的,并以此为基础计算一致性比率,你可以修改上述SQL查询如下:
```sql
WITH field_values AS (
SELECT
CASE
WHEN verifyCompetAmount = verCompetAm02 OR
verifyCompetAmount = verCompetAm03 OR
verCompetAm02 = verCompetAm03 THEN verifyCompetAmount
ELSE NULL
END AS common_value
FROM
your_table_name
)
SELECT
COUNT(*) * 1.0 / (SELECT COUNT(*) FROM field_values) AS consistency_rate
FROM
field_values
WHERE
common_value IS NOT NULL;
```
这里我们在`CASE`语句中添加了`OR`操作符,检查任意两个字段是否相等,如果相等就返回该值。
阅读全文