在使用left join时,我希望有一个搜索字符串参数-这将是动态的。所以,我有以下问题
pl_ids_tuple = 1477 //Playlist id
initial_query_string = '''select songs.id, songs.name, songs.artist, songs.album, songs.albumart, songs."albumartThumbnail", cpr.votes, is_requested from
(select id, name, artist, album, albumart, "albumartThumbnail" from (select song_id from core_plsongassociation where playlist_id in (%s))'''%pl_ids_tuple
songs = Song.objects.raw(initial_query_string + ''' as sinpl
left join songs on sinpl.song_id=id where explicit=False
) as songs left join
(select song_id, votes, bool_or(thirdpartyuser_id=%s) as is_requested from
(select * from core_priorityrequests where client_id=%s and is_played=False
) as clpr left join core_priorityrequests_third_party_user on clpr.id=priorityrequests_id
group by priorityrequests_id, song_id, votes
) as cpr on songs.id=cpr.song_id where songs.name ilike %s or songs.artist ilike %s limit %s offset %s
left join
(select core_blocksong.song_id from core_blocksong where core_blocksong.unblock_flag = 'f' and core_blocksong.client_id=%s)
as c on c.song_id = songs.id where c.song_id is null''',
[request.anon_user.id, restaurant.client.id,search_string,search_string,limit,offset,restaurant.client.id,])
如果你注意到/仔细观察,我得到一个编程错误,由于放置- songs.name ilike %s or songs.artist ilike %s limit %s offset %s
在查询中。
如果我把这个约束放在最后,那么响应就不同了。有人能建议我把这个约束放在哪里才能得到正确的响应吗?
我通读了这个资源-https://www.mysqltutorial.org/mysql-left-join.aspx/ 并发现加入后的过滤器在哪里。
暂无答案!
目前还没有任何答案,快来回答吧!