求助mssql语句转成mysql

gongshunkai3 2017-08-26 03:47:59
with t as (select * from Category where CatId = @CatId union all select a.* from Category as a inner join t as b on a.ParentId = b.CatId) select * from Goods where CatId in (select CatId from t)

mysql似乎不支持with,是不是要用create写个临时表,请大神帮忙写一下,本人对php不熟悉
...全文
194 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongshunkai3 2017-08-28
  • 打赏
  • 举报
回复
自己顶~~~~
gongshunkai3 2017-08-26
  • 打赏
  • 举报
回复
引用 1 楼 hongmei85 的回复:
没验证,看下对不对

select * from Goods where CatId in (select CatId from Category where CatId = @CatId union all select CatId from Category where ParentId = @CatId)



不对,请看结构图,比如商品表某条记录的CatId是6,那么 当分类是2,也能把商品表的CatId是6的记录找到,
简单的说,把某个分类(包括自己)的所有子分类的产品找到。

hongmei85 2017-08-26
  • 打赏
  • 举报
回复
没验证,看下对不对 select * from Goods where CatId in (select CatId from Category where CatId = @CatId union all select CatId from Category where ParentId = @CatId)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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