K
kofoun
Unregistered / Unconfirmed
GUEST, unregistred user!
关于sqlserver2000数据库查询语句的问题:
现时有一个如下的表table1,表结构如下:
-------------------------------------
fid int identity not null primary key
fdate datetime //日期
fline varchar(20) //生产线
fmaster varchar(20) //主任
fproductname varchar(60) //产品名称
fgoodscount int //成品数量
fprojectname varchar(60) //工程名称
fcheckcount int //检查总数
fcheckokcount int //合格数
fcheckproject varchar(60) //检查项目
fcheckng int //不合格数
foutcount int //出库数量
fperson int //人数
fdailytime numeric(5,1) //正常时间
fovertime numeric(5,1) //加班时间
ftotaltime numeric(5,1) //总时间
===============================
现时我按fdate,fline,fproductname分类汇总如下:
select fdate,fline,fproductname,sum(fgoodscount)goods,sum(fcheckng)ng,sum(fdailytime)dailytime,sum(fovertime)overtime,sum(ftotaltime)totaltime from bdailytable group by fdate,fline,fproductname
得出fgoodscount(goods),fcheckng(ng),fdailytime(daily),fovertime(over),ftotaltime(totaltime)总数
---------------------------------------------------------------------------------------
fdate fline fproductname goods ng daily over totaltime
2006-07-03 A5 HDR2150-150 8000 900 416.0 104.0 520.0
2006-07-04 A5 HDR2150-150 9000 829 488.0 122.0 610.0
2006-07-05 A5 HDR2150-150 10000 4 .0 .0 .0
2006-07-06 A5 HDR2150-150 NULL 106 184.0 46.0 230.0
2006-07-12 A5 HDR2150-150 10000 7 .0 .0 .0
2006-07-16 A5 HDR2150-150 7000 527 456.0 .0 456.0
2006-07-20 A1 HDR2150-042 500 30 40.0 10.0 50.0
问题1:我想在此查询结果中最右边增加一,列1: 显示(ng/(ng+goods)*100%)的百分比
fdate fline fproductname goods ng daily over totaltime 列1
2006-07-03 A5 HDR2150-150 8000 900 416.0 104.0 520.0 11.12%
2006-07-04 A5 HDR2150-150 9000 829 488.0 122.0 610.0 8.43%
2006-07-05 A5 HDR2150-150 10000 4 .0 .0 .0 0.03%
2006-07-06 A5 HDR2150-150 NULL 106 184.0 46.0 230.0 100%
2006-07-12 A5 HDR2150-150 10000 7 .0 .0 .0 0.06%
2006-07-16 A5 HDR2150-150 7000 527 456.0 .0 456.0 7.00%
2006-07-20 A1 HDR2150-042 500 30 40.0 10.0 50.0 5.66%
问题2:再在此查询中,再统计每个fproductname的总分类明细,想得出如下结果:
fgoods goods ng (ng/(ng+goods))
HDR2150-150 44000 2373 5.11% (最要小数点后两位)
HDR2150-042 500 30 5.66%
现时有一个如下的表table1,表结构如下:
-------------------------------------
fid int identity not null primary key
fdate datetime //日期
fline varchar(20) //生产线
fmaster varchar(20) //主任
fproductname varchar(60) //产品名称
fgoodscount int //成品数量
fprojectname varchar(60) //工程名称
fcheckcount int //检查总数
fcheckokcount int //合格数
fcheckproject varchar(60) //检查项目
fcheckng int //不合格数
foutcount int //出库数量
fperson int //人数
fdailytime numeric(5,1) //正常时间
fovertime numeric(5,1) //加班时间
ftotaltime numeric(5,1) //总时间
===============================
现时我按fdate,fline,fproductname分类汇总如下:
select fdate,fline,fproductname,sum(fgoodscount)goods,sum(fcheckng)ng,sum(fdailytime)dailytime,sum(fovertime)overtime,sum(ftotaltime)totaltime from bdailytable group by fdate,fline,fproductname
得出fgoodscount(goods),fcheckng(ng),fdailytime(daily),fovertime(over),ftotaltime(totaltime)总数
---------------------------------------------------------------------------------------
fdate fline fproductname goods ng daily over totaltime
2006-07-03 A5 HDR2150-150 8000 900 416.0 104.0 520.0
2006-07-04 A5 HDR2150-150 9000 829 488.0 122.0 610.0
2006-07-05 A5 HDR2150-150 10000 4 .0 .0 .0
2006-07-06 A5 HDR2150-150 NULL 106 184.0 46.0 230.0
2006-07-12 A5 HDR2150-150 10000 7 .0 .0 .0
2006-07-16 A5 HDR2150-150 7000 527 456.0 .0 456.0
2006-07-20 A1 HDR2150-042 500 30 40.0 10.0 50.0
问题1:我想在此查询结果中最右边增加一,列1: 显示(ng/(ng+goods)*100%)的百分比
fdate fline fproductname goods ng daily over totaltime 列1
2006-07-03 A5 HDR2150-150 8000 900 416.0 104.0 520.0 11.12%
2006-07-04 A5 HDR2150-150 9000 829 488.0 122.0 610.0 8.43%
2006-07-05 A5 HDR2150-150 10000 4 .0 .0 .0 0.03%
2006-07-06 A5 HDR2150-150 NULL 106 184.0 46.0 230.0 100%
2006-07-12 A5 HDR2150-150 10000 7 .0 .0 .0 0.06%
2006-07-16 A5 HDR2150-150 7000 527 456.0 .0 456.0 7.00%
2006-07-20 A1 HDR2150-042 500 30 40.0 10.0 50.0 5.66%
问题2:再在此查询中,再统计每个fproductname的总分类明细,想得出如下结果:
fgoods goods ng (ng/(ng+goods))
HDR2150-150 44000 2373 5.11% (最要小数点后两位)
HDR2150-042 500 30 5.66%