UNION查出来后使用代码拼接
This commit is contained in:
parent
e521c139e2
commit
4a245ceba4
@ -14,9 +14,12 @@ async function fetchAll({ args = {} }) {
|
||||
args.min ? `song_id > ${args.min}` : '1=1',
|
||||
args.max ? `song_id <= ${args.max}` : '1=1',
|
||||
].join(' AND ');
|
||||
var sql = `
|
||||
var sql1 = `
|
||||
SELECT song_id FROM song_artist_relation WHERE ${whereClause} AND song_id NOT IN ( SELECT song_id FROM song )
|
||||
UNION
|
||||
${args.order ? `ORDER BY song_id ${args.order}` : ''}
|
||||
${args.limit ? `LIMIT ${args.limit}` : ''}
|
||||
`;
|
||||
var sql2 = `
|
||||
SELECT song_id FROM song_album_relation WHERE ${whereClause} AND song_id NOT IN ( SELECT song_id FROM song )
|
||||
${args.order ? `ORDER BY song_id ${args.order}` : ''}
|
||||
${args.limit ? `LIMIT ${args.limit}` : ''}
|
||||
@ -25,10 +28,15 @@ async function fetchAll({ args = {} }) {
|
||||
// sql = `SELECT song_id FROM song WHERE data_version = 1`;
|
||||
// 测试用
|
||||
// sql = `SELECT song_id FROM song_artist_relation group by song_id limit 10`;
|
||||
console.log(sql);
|
||||
console.log(sql1);
|
||||
var songIds1 = await dbUtils.query(sql1, []);
|
||||
songIds1 = songIds1.map(item => item.song_id);
|
||||
|
||||
var songIds = await dbUtils.query(sql, []);
|
||||
songIds = songIds.map(item => item.song_id);
|
||||
console.log(sql2);
|
||||
var songIds2 = await dbUtils.query(sql2, []);
|
||||
songIds2 = songIds2.map(item => item.song_id);
|
||||
|
||||
var songIds = songIds1.concat(songIds2);
|
||||
songIds = Array.from(new Set(songIds)); // 去重
|
||||
|
||||
// 0 - 100, 200 - 399, 400 - ..., ... - songIds.length-1
|
||||
|
Loading…
Reference in New Issue
Block a user