mysql:14957
From: Yoshiaki Yanagimoto <Yoshiaki Yanagimoto <yanagimoto@xxxxxxxxxx>>
Date: Mon, 06 Jul 2009 17:12:39 +0900
Subject: [mysql 14957] Re: 複雑なdeleteの書き方
柳本です。
delete from [テーブル名]
where user_id in (
select user_id from [テーブル名]
where page_id = 1
and created + cast('7 days' as interval) > now()
)
こうですか?わかりません><
tysmk さんは書きました:
> お世話になっております。
>
> 以下のようなテーブルがあったと仮定します。
>
> id int auto_increment,
> user_id int,
> page_id int,
> created date,
> primary key(id),
> unique key(user_id,member_id,page_id)
>
> このテーブルから
> page_id=1 and created+ intarval 7 day > now()
> がtrueの場合、該当するuser_idのすべてを削除したいのですがどのように書け
> ばいいでしょうか?
>
> わかりやすく書くと舌のようにデータが入っていた場合、消えるのは
> id = 1 and id = 4
> になります。
>
> id user_id page_id created
> 1 1 1 2009-06-15
> 2 2 3 2009-07-05
> 3 2 1 2009-07-05
> 4 1 2 2009-07-05
>
>
> ご教示お願いいたします。
>
14954 2009-07-06 16:45 [tysmk <shu@xxxxxxxxx] 複雑なdeleteの書き方 14955 2009-07-06 16:57 ┣[<y-iida@xxxxxxxxxx> ] 14958 2009-07-06 17:15 ┃┗[tysmk <shu@xxxxxxxxx] -> 14957 2009-07-06 17:12 ┣[Yoshiaki Yanagimoto ] 14963 2009-07-06 18:14 ┃┗[tysmk <shu@xxxxxxxxx] 14964 2009-07-06 23:50 ┃ ┗[chuuken kenkou <ken_] 14965 2009-07-07 11:37 ┃ ┗["Kaname Kuji\(Y7\)" ] 14959 2009-07-06 17:42 ┣[Katsutoshi Nakatomi ] 14961 2009-07-06 17:57 ┃┗[tysmk <shu@xxxxxxxxx] 14962 2009-07-06 18:09 ┃ ┗[Katsutoshi Nakatomi ] 14966 2009-07-07 12:41 ┗["N.K." <nakai.kanako]