你的<>和=号是不是反了?select * from table1 where dateDiff(day,idate,getdate())=0 order by vip
union all
select * from table2 where dateDiff(day,idate,getdate())<>0 order by idate
union all
select * from table2 where dateDiff(day,idate,getdate())<>0 order by idate
union all
select * from table2 where dateDiff(day,idate,getdate())=0 order by vip
我预想的应是前面排的是今天发布的信息,并按VIP等级
然后显示完今天的再显示其它天的,并只按时间。如:
+------------------------------------+
| ID | VIP | IDate |
+------+----------+------------------+
| 01 | 2 | 2005-05-28 12:05 |
+------+----------+------------------+
| 02 | 1 | 2005-05-28 15:05 |
+------+----------+------------------+
| 03 | 0 | 2005-05-28 17:05 |
+------+----------+------------------+
| 04 | 0 | 2005-05-27 17:05 |
+------+----------+------------------+
| 05 | 2 | 2005-05-26 10:05 |
+------+----------+------------------+
| 06 | 1 | 2005-05-25 17:05 |
+------+----------+------------------+
from table1
order by case when dateDiff(day,idate,getdate())=0 then 0
else 1
end,
case when dateDiff(day,idate,getdate())=0 then vip
else idate
end desc