表一:tab1
字段:id,name,sex...表二:tab2
字段:id,name,sex...要求:用一条sql查询出表一中name为 “xx”的人数占表二中name为 “xx” 的人数的百分比(select count(id) from tab1 where name="xx")/(select count(id) from tab2 where name="xx")这样好像不行啊
字段:id,name,sex...表二:tab2
字段:id,name,sex...要求:用一条sql查询出表一中name为 “xx”的人数占表二中name为 “xx” 的人数的百分比(select count(id) from tab1 where name="xx")/(select count(id) from tab2 where name="xx")这样好像不行啊
解决方案 »
- ADObe ODBC 的问题,太抽象啦
- 客户的报表都要求任一时刻的库存,不知大家有什么好的解决方法。
- 同一列重复值的提取更新
- 再问:数据表字段该如何命名?
- SQL 语句难度
- alter 命令会有不良后果吗?
- sql2000 写入超过500个汉字的数据就是空值而且不是null 这是为什么啊
- 已禁用对分布式事务管理器(MSDTC)的网络访问。请使用组件服务管理工具启用 DTC 以便在 MSDTC 安全配置中进行网络访问。
- 有关存储过程加密的两个问题?
- 弱弱地问,在SQL server中用select语句检索数据时,where后面最多可以跟多少个and??
- sqlserver2000 重建索引
- 15毫秒insert一笔数据,用Access数据库行不行?
(select count(id) from tab1 where name="xx")/(select count(id) from tab2 where name="xx")??? 除数要判断是否为0
select
(select count(id) from tab1 where name='xx')/
nullif((select count(id) from tab2 where name='xx'),0)
select (select count(1)*1.0 from tb1 where name='xx')/(select count(1) from tb2 where name='xx')
[id] [int] NULL,
[code] [decimal](18, 2) NULL
) ON [PRIMARY]GOINSERT INTO [DBText].[dbo].[tb]
([id]
,[code])
VALUES
(<id, int,>
,<code, decimal(18,2),>)
GOCREATE TABLE [dbo].[tbs](
[id] [int] NULL,
[path] [varchar](100) NULL
) ON [PRIMARY]GOINSERT INTO [DBText].[dbo].[tbs]
([id]
,[path])
VALUES
(<id, int,>
,<path, varchar(100),>)
GOselect
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 count(id) from tab1 where name="xx")*100.0
/
(select count(id) from tab2 where name="xx")
as decimal(18,2))