select * from 你的表 a
where Flag = '出货' and date in (select max(date) from 你的表 where matcode = a.matcode)Union allselect * from 你的表 a
where Flag = '收货' and date in (select max(date) from 你的表 where matcode = a.matcode)
where Flag = '出货' and date in (select max(date) from 你的表 where matcode = a.matcode)Union allselect * from 你的表 a
where Flag = '收货' and date in (select max(date) from 你的表 where matcode = a.matcode)
解决方案 »
- MRP运算后的订单跟踪
- 触发器相关问题
- 表转化成 excel
- 如何在服务器控制非管理员用户只能看到它有管理权限的数据库呢?20分
- 请问怎个触发器怎么写
- 为什么我的SQL不能自动备份呀.运行AGENT,提示登录错误.我最近改了WIN的用户名.
- 昨天听石头,影子各位讲解DISTINCT后,有些头绪,今天有些地方又闷了!
- 2k professional环境,mssql 2000(personal)装不上去,都装了两天了,系统格了N次了
- 关于SQL求救!SQL高高手过来
- SQL问题请教:如何过滤重复记录.
- 帮我看看这个是什么问题!谢谢啊!
- 有一次我在打开企业管理器时弹出:MMC无法打开选择文件。 企业管理器打开失败,不如何办。谢谢!!
Group by matcode, Flag
select a.*
from tablename a join
( select matcode,[flag],max([date]) as md
from tablename
group by matcode,[flag]
) b
on a.matcode=b.matcode and a.flag=b.flag and a.date=b.md
WHERE a.date in
(selecr max(date) from 你的表 where matcode = a.matcode)
from tablename
group by matcode,[flag]