SQL 问题 请教一下
本帖最后由 hongliangc5dn 于 2013-07-18 18:45:29 编辑
环境 :SQL2005
错误 :遇到以零作除数错误。
SELECT
CASE WHEN complete IS NULL THEN 0 ELSE complete END AS complete,
CASE WHEN task IS NULL THEN 0 ELSE task END AS task
FROM
(SELECT
(select SUM(complete) FROM staff_base_number where flag = 1 and assess_time_id = 2 and staff_id = [temp].id) as complete,
(select SUM(task) FROM staff_base_number where flag = 1 and assess_time_id = 2 and staff_id = [temp].id) as task
FROM [staff] AS temp) as staff
order by complete/task desc ---这里报错
由于是批量排序 所以无法保证里complete都不为0 求解决办法
------解决方案--------------------用case when 试试看。