问题描述
- 求助大神一个sql 百分比的问题
- select a.contCLng((select count(*) as cs from [order] b where b.order_cont like '*'+a.cont+'*'))/CLng((select count(*) from [order] b)) from [order_cont] a
这个输出不出来每一行除完之后的数 求大神帮忙看看这个
解决方案
SELECT T1.ContSUM(IIF(T2.Order_Cont=T1.Cont 1 0))/(SELECT COUNT(*) FROM [Order])FROM (Order_Cont T1 LEFT JOIN [Order] T2 ON T1.Cont = T2.Order_Cont)GROUP BY T1.Cont
解决方案二:
因为你是模糊查询,所以用LIKE
SELECT T1.ContSUM(IIF(T2.Order_Cont=T1.Cont 1 0))/(SELECT COUNT(*) FROM [Order])FROM (Order_Cont T1 LEFT JOIN [Order] T2 ON T2.Order_Cont LIKE '*' + T1.Cont + '*')GROUP BY T1.Cont
时间: 2024-11-08 18:14:45