这是我从数据库查询出来的数据,只是通过时间排序了下,现在我还要在时间排序的前提下再将社区头条放在时间段的第一位
效果是这样的
现在怎么写SQL语句能得到我想要的结果,或者通过将数据传入一个临时表,但我不知道怎么写
select c.* from (select a.articleTitle,a.createTme,b.catName from t_zx_sqzx a,t_zx_xiaoqu b where a.catId=b.catId and a.isHow='1' and a.communityId='8' and a.createTime>='2015-08-30' and a.createTime<='2015-09-02' order by createTime) c order by catName
你把你以时间排序查询出来的数据作为一个table,在以这个table按catName排序查询。你试试!!
select * from (select a.articleTitle,a.createTime,b.catName
from t_zx_sqzx a,t_zx_xiaoqu b
where a.catId = b.catId and a.isShow = '1' and a.communityId = '8' and a.createTime>='2015-08-30' and a.createTime<='2015-09-02'
order by createTime) where a.artticleTitle = '最后测试'
先按照一个字段排序,然后把排序后独处来的记录作为一张新表,在按照另一个字段去排序
两张临时表之间根本就没有关联条件,怎么能拼成一张表呢,最多只能拼成组合表,比如下面的形式,
select a.articleTitle,a.createTme,b.catName from t_zx_sqzx a,t_zx_xiaoqu b where a.catId=b.catId and a.isHow='1' and a.communityId='8' and a.createTime>='2015-08-30' and a.createTime<='2015-09-02' order by createTime,catName
有点没明白LZ的意思呢,是想说排序方式为catName+createTime吗?
SELECT a.articleTitle,a.createTme,b.catName
FROM t_zx_sqzx a,t_zx_xiaoqu b
WHERE a.catId=b.catId AND a.isHow='1' AND a.communityId='8' AND a.createTime>='2015-08-30' AND a.createTime<='2015-09-02'
ORDER BY catName,createTime