union all使用怪现象,请高手解答!
想实现如下功能:会员信息总是放在最前面(按时间排序),当会员信息全部输出时才输出非会员信息(按时间排序),用union all实现时有如下怪现象,请高手解答,
(表名:gongying,字段名:g_title(标题),g_image(图像),g_date(日期),ifvip(会员识别符号))
sql= "select * from (select g_title,g,image,g_date from gongying where ifvip=1 order by g_date desc
union all
select g_title,g,image,g_date from gongying where ifvip=0 order by g_date desc) "
调试能输出会员信息\非会员信息,但会员信息与非会员信息交替,无实现会员信息在前的功能!
sql= "select * from (select g_title,g,image,g_date from gongying where ifvip=1 order by g_date desc) as A
union all
select * from (select g_title,g,image,g_date from gongying where ifvip=0 order by g_date desc) as B "
调试能输出会员信息\非会员信息,且实现会员信息在前的功能!但会员信息内部排序无按g_date desc来排序,非会员信息内部也没有按g_date desc排序!
如何才能实现???
------解决方案--------------------你這個可以不使用union all
try
sql= "select g_title,g,image,g_date from gongying order by ifvip Desc, g_date desc "