请帮忙看一下
SELECT a.gs, b.zgs, CASE WHEN b.zgs > 0 THEN (a.gs / b.zgs)
ELSE 0 END AS jg FROM (SELECT COUNT(*) gs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '张** ') a CROSS JOIN
(SELECT COUNT(*) zgs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '李** ') b
为什么相除的结果是 '0 ' 小数加不上
------解决方案--------------------SELECT a.gs, b.zgs, CASE WHEN b.zgs > 0 THEN (cast(a.gs as decimal) / cast(b.zgs as decimal))
ELSE 0 END AS jg FROM (SELECT COUNT(*) gs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '张** ') a CROSS JOIN
(SELECT COUNT(*) zgs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '李** ') b
------解决方案--------------------SELECT a.gs, b.zgs, CASE WHEN b.zgs > 0 THEN (a.gs*1.0 / b.zgs)
ELSE 0 END AS jg FROM (SELECT COUNT(*) gs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '张** ') a CROSS JOIN
(SELECT COUNT(*) zgs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '李** ') b
------解决方案--------------------SELECT a.gs, b.zgs, CASE WHEN b.zgs > 0 THEN a.gs / cast(b.zgs as decimal(10,2)))
ELSE 0 END AS jg FROM (SELECT COUNT(*) gs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '张** ') a CROSS JOIN
(SELECT COUNT(*) zgs
FROM tljtjh.dbo.jhxjk
WHERE djbz = '李** ') b