select col1=(select colname from tb where ...),col2,col3 from tablename
SELECT (SELECT A FROM B WHERE ID=1)
select id,name=(select min(name) from tb) from tb 用这种方式会提示未找到预期的from 关键字
select *,(select XX from tb where XX ) from tb
---要看你的数据,和具体要求 if object_id('tb')is not null drop table tb go create table tb(id int,name int) insert tb select 1,11 union all select 1,12 union all select 1,13 union all select 2,14 union all select 3,15 union all select 4,16 union all select 5,17select id,name=(select min(name) from tb) from tb id name ----------- ----------- 1 11 1 11 1 11 2 11 3 11 4 11 5 11(7 行受影响)
--sql 2005 with tablename as (select * from tb ) select * from tablename where ...
SELECT (SELECT A FROM B WHERE ID=1) 因为我语句中含有sum语句 所以还会提示非单组分组函数
select sum(f.jine),(select zyh from zl where jzh='266165') from ndns.zl a,mx f,ndns.test_1 g where a.jzh = f.jzh and f.xmdm = g.xmdm 我用的是Oracle数据库,这条语句提示非单组分组函数
select sum(f.jine) from ndns.zl a,mx f,ndns.test_1 g where a.jzh = f.jzh and a.jzh ='266165' and f.xmdm = g.xmdm sumsum(f.jine) 1186.32(1行受影响) select zyh from zl where jzh='266165' zyh 00113979(1行受影响) 当两个语句合并的时候就报非单组分组函数
select from
from
select t.* from
(select * from dbo.Customers) t
select id,name=(select min(name) from tb) from tb
(SELECT A FROM B WHERE ID=1)
from tb
if object_id('tb')is not null drop table tb
go create table tb(id int,name int)
insert tb select
1,11 union all select
1,12 union all select
1,13 union all select
2,14 union all select
3,15 union all select
4,16 union all select
5,17select id,name=(select min(name) from tb) from tb
id name
----------- -----------
1 11
1 11
1 11
2 11
3 11
4 11
5 11(7 行受影响)
--sql 2005
with tablename
as
(select * from tb
)
select * from tablename
where ...
(SELECT A FROM B WHERE ID=1) 因为我语句中含有sum语句 所以还会提示非单组分组函数
from ndns.zl a,mx f,ndns.test_1 g
where a.jzh = f.jzh
and f.xmdm = g.xmdm
我用的是Oracle数据库,这条语句提示非单组分组函数
from ndns.zl a,mx f,ndns.test_1 g
where a.jzh = f.jzh
and a.jzh ='266165'
and f.xmdm = g.xmdm
sumsum(f.jine)
1186.32(1行受影响)
select zyh from zl where jzh='266165'
zyh
00113979(1行受影响)
当两个语句合并的时候就报非单组分组函数