一张表中有images2,images,cph,xm,rq、flag,kh等字段,并且images2和images插入记录时只能填一个字段,我现在想通过一条sql语句把images和images2同时在一行显示出来并且要把一定时间段内满足条件的记录全部显示出来我是这样写的:select max(case when flag='进口机' then images2 end)images2,max(case when flag='出口机' then images end)images,cph from jcjl2 where datediff(day,rq,getdate())>=tpbcts and images2 is not null and images is not null group by cph但是这样写的话只能查询出一条记录,比如cph='粤C47484'的最近几天的一条记录。不会把车牌号为'粤C47484'的所有记录都统计出来,应该怎样才能全部统计出来。在线等。
其中tpbcts为图片保存天数。
其中tpbcts为图片保存天数。
解决方案 »
- SQL中如何对两张不同的表模糊查询
- Sql server触发器的问题
- 这个sql语句,困惑了好几天了,请高手帮忙吧,谢谢 100分 解决就结贴
- 索引。存储过程。我承认我是小白。。求解。谢谢
- EXECL数据导入SQL SERVER 2005出现错误
- 关于dateadd函数的时间限制
- 历史问题,再次拿出来问。
- update触发器能不能不再触发?(找高手)
- 跪求.在线等
- 为什么VFP通过ODBC连接远程数据库可以如此快,而VB就这么慢,不管是128K专线还是56KMODEM,VB总是VFP的数倍时间!谁来给个合理的解释,谁来给个解决的方法,挽救VB!!
- SqlServer中有类似Oralce的connect by 递归查询么?
- sql语句里能否包含自定义函数
(case when flag='出口机' then images end)images,cph
from jcjl2 where datediff(day,rq,getdate())>=tpbcts
and images2 is not null and images is not null
max(case when flag='出口机' then images end)images
from jcjl2
where datediff(day,rq,getdate())>=tpbcts and images2 is not null and images is not null group by cph,rq
flag varchar(10),kh varchar(10))select (case when flag='进口机' then images2 end)images2,
(case when flag='出口机' then images end)images,cph
from @t
where datediff(day,rq,getdate())>=1
and images2 is not null and images is not null /*images2 images cph
---------- ---------- ----------- (所影响的行数为 0 行)
*/