select *
from(
select Id,Mid,Picture,ids=row_number()over(partition by Mid order by getdate())
from News
where Mid in (118,260,123,144,143,288) and Picture<>''
)a
where ids<3
order by Mid,Id
union all
select *
from(
select Id,Mid,Picture,ids=row_number()over(partition by Mid order by getdate())
from News
where Mid in (118,260,123,144,143,288) and Picture=''
)b
where ids<8
order by Mid,Id
这个查询提示“关键字 'union' 附近有语法错误。”请各位帮忙合并一下。或者有没有其他更好的办法来写这个sql语句
------解决思路----------------------
select *
from(
select Id,Mid,Picture,ids=row_number()over(partition by Mid order by getdate())
from News
where Mid in (118,260,123,144,143,288) and Picture<>''
)a
where ids<3
--order by Mid,Id
union all
select *
from(
select Id,Mid,Picture,ids=row_number()over(partition by Mid order by getdate())
from News
where Mid in (118,260,123,144,143,288) and Picture=''
)b
where ids<8
order by Mid,Id