我尝试只选择重量超过所有狗平均体重的狗。
我有这个SQL查询:
{{ ($website) ? $website->stats : null }}
如果我提示30而不是AVG(weigth),我会得到我正在寻找的结果。
你能解释一下我输入“AVG(...)”时没有结果的原因吗?
答案 0 :(得分:2)
SELECT nameAni, weigth
FROM Animal
WHERE idTpAni IN (SELECT idTpAni
FROM TypeAnimal
WHERE Lower(libTpAni) = 'dog')
AND weigth > (SELECT Avg(weigth)
FROM Animal
WHERE idTpAni IN (SELECT idTpAni
FROM TypeAnimal
WHERE Lower(libTpAni) = 'dog'))
如果您想以简单的方式进行,请参阅以下
DECLARE @weight FLOAT; --mind the type of this variable
SELECT @weight=Avg(weigth)
FROM Animal
WHERE idTpAni IN (SELECT idTpAni
FROM TypeAnimal
WHERE Lower(libTpAni) = 'dog')
SELECT nameAni, weigth
FROM Animal
WHERE idTpAni IN (SELECT idTpAni
FROM TypeAnimal
WHERE Lower(libTpAni) = 'dog')
AND weigth > @weight
答案 1 :(得分:0)
for (int i = 0; i < itemList.GetLength(1); i++) {
itemList [0,i] = itemList [1,i];
}
考虑使用分区而不是分组依据。