如何获得条件? [英] how to get where condition ?

查看:72
本文介绍了如何获得条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存选择输出以使用它

例如:

table1:

userid | date |
____________
1 | 27/3/2010
2 | 27/1/2010
1 | 28/2/2011
2 | 6/4/2011
_______________


table2:
雕像|用户ID
_______________
有效| 1
活跃| 2
_____________


我从table1中获取最后插入的日期,并与datenow比较

"select  DISTINCT userid,MAX(date)as date from table1 group by userid"



如何获得结果和

update table2 where table2.userid=???????



什么是条件条件??????????????????????????????????? br/>

  UPDATE 表2
 SET 状态= ' 有效'
位置 Table2.UserId  IN ( SELECT   DISTINCT 用户ID
                        来自 table1
                        位置 日期> DATEADD(天,-5,GETDATE()))
 AND  Table2.Status<> ' 有效' 

如果日期列中的日期为大于五天前.

但是,如果状态取决于不确定性值(例如当前日期,该值会不断变化),那么我不建议存储状态,只是建议在需要时查询状态.


i want to save select output to use it

example:

table1:

userid|date|
____________
1 |27/3/2010
2 |27/1/2010
1 |28/2/2011
2 |6/4/2011
_______________


table2:
statues|userid
_______________
active |1
active |2
_____________


i get last inserted date from table1 and compare to datenow

"select  DISTINCT userid,MAX(date)as date from table1 group by userid"



how to get result and

update table2 where table2.userid=???????



what is the where condition????

解决方案

You didn''t specify the logic very much so if I understood correctly, your update could be something like:

UPDATE Table2
SET Status = 'Active'
WHERE Table2.UserId IN (SELECT DISTINCT userid
                        from table1 
                        WHERE date > DATEADD( day, -5, GETDATE()))
AND Table2.Status <> 'Active'

The above should update the status to active if the date in date column is greater than five days ago.

However if the status is dependent on nondeterministic value (such as current date, which constantly changes), I wouldn''t advice to store the status, just to query the status when it''s needed.


这篇关于如何获得条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆