34,590
社区成员
发帖
与我相关
我的任务
分享
select cast(
(select count(id) from tab1 where name="xx")*100.0
/
(select count(id) from tab2 where name="xx")
as decimal(18,2))
CREATE TABLE [dbo].[tb](
[id] [int] NULL,
[code] [decimal](18, 2) NULL
) ON [PRIMARY]
GO
INSERT INTO [DBText].[dbo].[tb]
([id]
,[code])
VALUES
(<id, int,>
,<code, decimal(18,2),>)
GO
CREATE TABLE [dbo].[tbs](
[id] [int] NULL,
[path] [varchar](100) NULL
) ON [PRIMARY]
GO
INSERT INTO [DBText].[dbo].[tbs]
([id]
,[path])
VALUES
(<id, int,>
,<path, varchar(100),>)
GO
select
cast(cast((
( (select cast( COUNT(*) as decimal(18, 4)) from tbs) /nullif((select cast(COUNT(*)as decimal(18, 4)) from tb ),0))
*100) as decimal(18, 2)) as varchar(50)) +'%'
as 个数百分比
个数百分比
---------------------------------------------------
14.29%
(1 行受影响)
select (select count(1)*1.0 from tb1 where name='xx')/(select count(1) from tb2 where name='xx')
select
(select count(id) from tab1 where name='xx')/
nullif((select count(id) from tab2 where name='xx'),0)