2017-04-15 7 views
0

私はユーザーギャラリーをアップロードするテーブルを持っています。 gallery.created_atのユーザーが2か月以上アップロードされている必要があります。 私はこれを試してみましたが、それは私に0結果Mysql- 2か月以上アップロードされたデータを選択します。

select `galleries`.`client_id` as `client_id`, 
     `users`.`first_name` as `first_name` from `galleries` 
     inner join `users` on `users`.`id` = `galleries`.`client_id` 
     where `galleries`.`session_id` is null and 
     `galleries`.`is_video` = '1' and `galleries`.`is_thumb` = '1' and 
     galleries.created_at >= galleries.created_at - INTERVAL 2 MONTH 
    `galleries`.`client_id` not in (select `client_id` from 
     `orders`) 

答えて

1

を与えている問題はここにある:

galleries.created_at >= galleries.created_at - INTERVAL 2 MONTH 

と行方不明AND。おそらく、

curdateは何が必要です:

select g.client_id as client_id, 
    u.first_name as first_name 
from galleries g 
inner join users u on u.id = g.client_id 
where g.session_id is null 
    and g.is_video = '1' 
    and g.is_thumb = '1' 
    and g.created_at <= curdate() - INTERVAL 2 MONTH 
    and g.client_id not in (
     select client_id 
     from orders 
     ) 

要件が2ヶ月以上ため、アップロードを述べたので、私は<=を使用しました。

+0

これは、galleries.created_atとcrrent_dateの間のデータを返します.2ヶ月、つまり2月15日〜2017日です。 galleries.created_atが2か月以上経過しているデータが必要です – baig772

+0

@ baig772 - あなたが質問で言ったように '<='が必要です - '2ヶ月以上アップロードしました ' – GurV

+0

もそれを試しました。 – baig772

関連する問題