zgfp.net
当前位置:首页 >> sql语句,分别删除每个A字段下B字段最大的记录,应... >>

sql语句,分别删除每个A字段下B字段最大的记录,应...

比如表名为 tb11 方法一: delete tb11 from tb11 t, ( select a,max(b) as b from tb11 group by a ) r where t.a=r.a and t.b=r.b ---方法二: delete tb11 from tb11 q, ( select * from tb11 t where not EXISTS (select * from tb11 where a=...

select max(id) id,name from 表 group by name --如果表中还有其他字段要查出,那么 select * from 表 where id in (select max(id) from 表 group by name )

select min(a),b,c from A表 group by b,c 或者 select max(a),b,c from A表 group by b,c

在sql语句中求和函数使用sum(),但该函数只允许对数值型字段进行求和,如整型,实型,货币型等字段,二不允许对诸如字符型,日期型字段进行求和,对该题可以通过这样的语句实现,select 字段a,sum(字段b) from 表名 group by a字段

若A里的a字段要等于B中的b字段就用1L的写法,若是包含就这么写 select * from A where exists (select 1 from B where A.a like '%'+B.b+'%')

Sql Server 如下: 一: select * from a where exists (select 1 from b where code='S' and b.value+',' like '%'+a.it+',%' ) 二: select * from a where (select count(1) from b where code='S' and b.value+',' like '%'+a.it+',%' ) >0

你是要更新数据,还是增加数据: 增加数据: insert B(b) select a from A where ... 更新数据: update B set B.b = A.a from A where ...

1. select count(B) from tb where B='b' and A=2 and id in (select top 50 id from tb order by id desc) 2. select A,count(B) from tb where B='b' and A=2 and id in (select top 50 id from tb order by id desc) group by A

Select a.code,a.name,b.name2 from a left join (Select distinct name1, name2=(select name2+',' from b where name1=t.name1 for xml path('') ) from b as t) as b on a.name=b.name1 差不多就这个样子吧

SELECT MAX(b) FROM 表 GROUP BY a

网站首页 | 网站地图
All rights reserved Powered by www.zgfp.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com