mysql 报错 ‘u'Subquery returns more than 1 row'’

时间:2023-01-05 23:12:27
watch_course_sql = """select  DATE_FORMAT( FROM_UNIXTIME(a.CreateTime / 1000) , '%%Y-%%m-%%d %%T') regtime,
    a.username
FROM
    bskuser a
where
    a.UserName
in
    (select
        username
          from
            bskchapterlist
                where
                    lessonid =
                        (select
                                id
                            from
                                bsklesson a
                            WHERE
                                a.lessonname like \'%s\')
                            )
limit   %d,50

""" % (coursename, page*50)

 

前台传来的coursename应该是汉字

但是如果错误传来number的时候 

后台会报错 
    
‘u'Subquery returns more than 1 row'’        只需在在相关的位置加个any就行啦
最终的sql语句
  
select  DATE_FORMAT( FROM_UNIXTIME(a.CreateTime / 1000) , '%Y-%m-%d %T') regtime,
            a.username username
        FROM
            bskuser a
        where
            a.UserName
        in
             (select
                username
                  from
                    bskchapterlist
                        where
                            lessonid =
                                ANY (select
                                        id
                                    from
                                        bsklesson a
                                    WHERE
                                        a.lessonname like '%2%')
                                    )

 

相关资料:http://*.com/questions/778239/mysql-subquery-returns-more-than-one-row