以下是2个查询:
SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_SIT_CNT
FROM BUG
WHERE BUG.BG_USER_02 = 'SIT'
SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_UAT_CNT
FROM BUG
WHERE BUG.BG_USER_02 = 'UAT'
如何编写查询以使用上述查询的结果并执行以下操作:
缺陷去除效率:BUG_ID_SIT_CNT/(BUG_ID_SIT_CNT + BUG_ID_UAT_CNT)
答案 0 :(得分:5)
SELECT BUG_ID_SIT_CNT * 1. / BUG_ID_ALL
FROM (
SELECT
COUNT(CASE WHEN BG_USER_02 = 'SIT' THEN BG_BUG_ID END) AS BUG_ID_SIT_CNT,
COUNT(BG_BUG_ID) AS BUG_ID_ALL
FROM BUG
WHERE BG_USER_02 IN ('SIT', 'UAT')
) t
答案 1 :(得分:3)
您可以在
之类的外部查询中获取它SELECT BUG_ID_SIT_CNT/(BUG_ID_SIT_CNT + BUG_ID_UAT_CNT) as testcol
FROM (
SELECT SUM(CASE WHEN BUG.BG_USER_02 = 'SIT' THEN 1 ELSE 0 END) AS BUG_ID_SIT_CNT,
SUM(CASE WHEN BUG.BG_USER_02 = 'UAT' THEN 1 ELSE 0 END) AS BUG_ID_UAT_CNT
FROM BUG ) xx;
答案 2 :(得分:1)
您可以将两个查询包装在WITH语句中,然后在SELECT中执行计算。
答案 3 :(得分:0)
WITH sit
AS
(
SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_SIT_CNT
FROM BUG
WHERE BUG.BG_USER_02 = 'SIT'
),
uat
AS
(
SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_UAT_CNT
FROM BUG
WHERE BUG.BG_USER_02 = 'UAT'
)
SELECT sit.BUG_ID_SIT_CNT/(sit.BUG_ID_SIT_CNT + uat.BUG_ID_UAT_CNT)
FROM sit, uat
答案 4 :(得分:0)
我会用参数来做,因为我发现它更具可读性:
<template>
<form method="post" action="" v-on:submit.prevent="search">
<input type="text" placeholder="Person name" required v-model="name" v-el="nameInput" />
<input type="text" placeholder="Company" required v-model="company" v-el="domainInput" />
<input type="submit" value="Search" class="btn show-m" />
</form>
</template>
<script>
export default {
data () {
return {
contacts: [],
name: null,
company: null
}
},
ready: {
// I tried the following :
this.$$.nameInput.focus();
this.$els.nameInput.focus();
// None of them worked !
}
methods: {
search: function (event) {
// ...
// I also would like to give the focus here, once the form has been submitted.
// And here also, this.$$ and this.$els doesn't work
},
}
}
</script>
答案 5 :(得分:0)
SELECT cast(BUG_ID_SIT_CNT as decimal) / cast((BUG_ID_SIT_CNT + BUG_ID_UAT_CNT)as decimal)
FROM (
SELECT
COUNT(CASE WHEN BG_USER_02 = 'SIT' THEN BG_BUG_ID END) AS BUG_ID_SIT_CNT
COUNT(CASE WHEN BG_USER_02 = 'UAT' THEN BG_BUG_ID END) AS BUG_ID_UAT_CNT
FROM BUG
WHERE BG_USER_02 IN ('SIT', 'UAT')
) t