sql refine实例

来源:互联网 发布:阿里云客服报名关闭 编辑:程序博客网 时间:2024/06/01 20:06

代码写的好不好,不在于语言,在于写代码的人。

谁都知道这个道理!?

sql有段代码这么写:

        $sql = 'SELECT count(*) as count from( select m.id AS meta_id, m.uuid,m.thumbnail_url, m.status, m.title, m.is_auto_release, m.is_edited,a.id AS attr_id, a.video_url';        $sql .= ' FROM vms_video_metadata m, vms_video_attribute a';        $sql .= ' WHERE m.creator_id = ? AND m.uuid = a.uuid AND (a.video_type = ? OR a.video_type = ?)  And m.slice_type !="slice_c" ';        if ($isEdited) {            $sql .= ' AND m.is_edited = ' . $isEdited;        }        if ($transcodeType) {            $sql .= ' AND m.status = ' . $transcodeType;        } else {            $sql .= ' AND m.status <> '. NOT_RELEASE;        }        $sql .= ' ORDER BY m.id desc, a.id desc ) j';

谁知道这个鬼sql是干什么的。

最后执行的sql是:

SELECT count(*) as count from(    select m.id AS meta_id, m.uuid, m.thumbnail_url, m.status, m.title, m.is_auto_release, m.is_edited, a.id AS attr_id, a.video_url     FROM vms_video_metadata m, vms_video_attribute a     WHERE m.creator_id = ? AND m.uuid = a.uuid AND (a.video_type = ? OR a.video_type = ?)          And m.slice_type !="slice_c"  AND m.is_edited = all AND m.status <> 7 ORDER BY m.id desc, a.id desc ) j;

改改:

select count(m.id) from vms_video_metadata m, vms_video_attribute a     where m.creator_id = 1 AND m.uuid = a.uuid AND (a.video_type = 'upload' OR a.video_type = 'quick_edit')      And m.slice_type !="slice_c"  AND m.is_edited = 'all' AND m.status <> 7


0 0
原创粉丝点击