msyql多个where语句

时间:2017-07-22 09:32:30

标签: mysql

SELECT
                              `pid`,
                              `uid`,
                              `created_date`,
                               UNIX_TIMESTAMP(`created_date`) as created_date_timestamp,
                              `updated_date`,
                              `post_status`,
                              `post_visibility`,
                              `post_content_availability`,
                              `content`,
                              `images_count`,
                              `videos_count`,
                              `media_availability`,
                              `images_availability`,
                              `videos_availability`
                              `up_count`,
                              `down_count`,
                              `comments_count`,
                              `comments_availability`,
                              `post_type`,
                              `post_max_date`,
                              `contans_feeling`,
                              `contans_activity`,
                              `feeling_type`,
                              `activity_type`,
                              `activity_about`,
                              `post_hashtag`,
                              `currency_type`,
                              (SELECT CONCAT(`first_name`, ' ', `last_name`)  FROM `users` WHERE `uid` = t1.`uid` LIMIT 1) AS user_name,
                              IFNULL((SELECT `upid` FROM `post_ups` WHERE `pid` = t1.`pid` AND `uid` = '$uid' AND `up_status` = 1 LIMIT 1),'-1') AS ups_status,
                              IFNULL((SELECT `upid` FROM `post_downs` WHERE `pid` = t1.`pid` AND `uid` = '$uid' AND `down_status` = 1 LIMIT 1),'-1') AS downs_status,
                              (SELECT `file_name` FROM `profile_images` WHERE `uid` = t1.`uid` AND `active` = '1' LIMIT 1) AS profile_image,
                              (SELECT CONCAT(
                                '[',
                                                    GROUP_CONCAT(json_object('image_width',image_width,'image_height',image_height,'image_name', image_name, 'iid', iid)),
                                ']'
                            )
                            FROM posts_images WHERE pid = t1.`pid`) AS posts_images,
                            (SELECT CONCAT(
                                '[',
                                                    GROUP_CONCAT(json_object('video_name', video_name, 'vid', vid)),
                                ']'
                            )
                            FROM posts_videos WHERE pid = t1.`pid`) AS post_videos,
                            IFNULL(
                                                    (SELECT
                                                    CONCAT('{','username:\"',
                                                        (SELECT CONCAT(`first_name`, ' ', `last_name`)  FROM `users` WHERE `uid` = t4.`uid` LIMIT 1) ,'\",',
                                                           'comment_content:\"',
                                                      `comment_content`,'\",',
                                                           'profile_image:\"',
                                                       (SELECT `file_name` FROM `profile_images` WHERE `uid` = t4.`uid` AND `active` = '1' LIMIT 1),'\"}')
                                                    FROM
                                                      `posts_comments` t4
                                                    WHERE
                                                      `pid` = t1.`pid` ORDER BY `comment_date` DESC LIMIT 1),'false') AS post_comemnts
                            FROM
                              `users_posts` t1
                            WHERE
                   (`created_date` < '$last_post_date')  AND (`post_status` = '1')  "
                . " AND (`post_max_date` IS NULL OR `post_max_date` > now()) "
                . " AND (`uid` = '$uid'  OR t1.`uid` IN (SELECT `user_1_uid` FROM `users_connections` WHERE `user_2_uid`='$uid' AND `connections_status`=1)) "
                . "ORDER BY `created_date` DESC LIMIT 30;
  

WHERE                      (created_date&lt;'$ last_post_date')AND(post_status ='1')“                   。 “AND(post_max_date IS NULL或post_max_date&gt; now())”                   。 “AND(uid ='$ uid'或t1。uid IN(SELECT user_1_uid FROM users_connections WHERE user_2_uid ='$ uid'AND   connections_status = 1))“                   。 “ORDER BY created_date DESC LIMIT 30;

我试图运行上面的查询,但结果是错误的,我想有些条件是失败的,“OR”语句中的问题是否覆盖了“AND”条件? ,我能做些什么来解决这个问题?

1 个答案:

答案 0 :(得分:0)

对不起我的坏,我需要抽烟,我只是重新排列条件的地方,并在sqlite数据库中存在局部冲突