select * from 表 A where invoice_id =(select top 1 invoice_id from 表 where user_id=A.user_id)
解决方案 »
- 求在sql server下的一个sql 语句的解释
- 请教一个简单的sql语句
- 两表结构一样,想将一个表中的数据合并到中一个表中,语句如何写?
- 当数据库里的数据大于3万条时,是否采用存储过程比直接使用sql代码会快很多呢?
- 动态创建触发器出现了问题 救命
- sql server2000使用select count(某字段名) from table提示"在这一子查询或聚合表达式中,text、ntext 和 image 数据类型无效。"
- 數據庫中的數據復制功能
- 删除数据库日志的问题 急!在线等
- 关于“SQLserver2000安装的问题”在线等.........
- yang_,j9988(j9988)看过来,续【触发器】问题。
- **____为什么我在ultraedit中带汉字的存储过程,复制到分析器中就全变乱码了___**
- 求一复杂sql!!急用谢谢
insert @tb
select 656789,9097 union all
select 656756,9097 union all
select 656555,9097 union all
select 676549,9097 union all
select 700128,8423 union all
select 718901,98526 union all
select 715092,98526 union all
select 448926,2751 union all
select 517855,2751 union all
select 485157,2751 select * from @tb A where invoice_id =(select top 1 invoice_id from @tb where user_id=A.user_id)--结果
/*invoice_id user_id
----------- -----------
656789 9097
700128 8423
718901 98526
448926 2751(所影响的行数为 4 行)
*/
(select max(invoice_id) + '-' + [userid] from test Group by [user_id])