SQL语句合并,求指点,谢谢

兽兽 2018-04-26 04:20:52

$sql='select a.id,nav,title,attr,color,date
from mall_article a
where 5 > (select count(*) from mall_article b where nav = a.nav and date > a.date and nav in(79,78,1))
and nav in(79,78,1)
order by a.date DESC';


想在上面的语句当中加入
$sql2='SELECT id,title,attr,color FROM mall_article order by rand() limit  5;';


...全文
1044 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
兽兽 2018-04-27
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
本来 where 5 > (select count(*) from mall_article b where nav = a.nav and date > a.date and nav in(79,78,1)) 的目的是分组后每组不超过 5条 你现在并没有分组,就有蛇足之嫌了
select id,nav,title,attr,color,date 
  from mall_article
  where nav in(79,78,1)
  order by rand() limit  5
这不和第二条一样的意思嘛。 可以分组5条的同时,再随机出5条吗
xuzuning 2018-04-26
  • 打赏
  • 举报
回复
本来 where 5 > (select count(*) from mall_article b where nav = a.nav and date > a.date and nav in(79,78,1)) 的目的是分组后每组不超过 5条
你现在并没有分组,就有蛇足之嫌了

select id,nav,title,attr,color,date 
from mall_article
where nav in(79,78,1)
order by rand() limit 5

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧