【发布时间】:2016-03-21 23:09:16
【问题描述】:
我正在尝试计算平均值、最小值、最大值、总数、计数,但我得到了错误的结果。
SELECT t0.brandID, t0.brandName, t0.cdt, t0.udt, t0.brandstatus, t0.AddedBy ,
AVG(t0.brandID) AS brandID_AVERAGE,
min(t0.brandid) as branid_min,
MAX(t0.brandid) as brandid_max,
COUNT(t0.brandid) as brandid_count
FROM brands t0
Where t0. brandID=null OR t0. brandName='khasim'
group by t0.brandID,t0.brandName,t0.cdt,t0.udt,t0.brandstatus,t0.AddedBy
select AVG(CAST (brandID AS bigint)) AS brandID_AVERAGE,
min(CAST (brandID AS bigint)) as branid_min,
MAX(CAST (brandID AS bigint)) as brandid_max,
COUNT(CAST (brandID AS bigint)) as brandid_count from
(SELECT t0.brandID, t0.brandName, t0.cdt, t0.udt, t0.brandstatus, t0.AddedBy
FROM brands t0
Where t0. brandID=null OR t0. brandName='budwieser'
group by t0.brandID,t0.brandName,t0.cdt,t0.udt,t0.brandstatus,t0.AddedBy) temptable
我已将我的查询更改为选择 avg 等作为现在选择的结果 我得到了我所期望的,但我想显示所有选定的列 一张桌子怎么办。
【问题讨论】:
-
替换 t0.brandid=null 为 null
-
@TheGameiswar,确保它是
t0.brandId is null。is和null之间的空格很重要。 -
是的,那是类型,我早就编辑过了
标签: sql-server-2008