Eyoucms程序开发:视图查询
视图查询可以实现不依赖数据库视图的多表查询,并不需要数据库支持视图,例如:
Db::view('User','id,name')
->view('Profile','truename,phone,email','Profile.user_id=User.id')
->view('Score','score','Score.user_id=Profile.id')
->where('score','>',80)
->select();
生成的SQL语句类似于:
SELECT User.id,User.name,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80
注意,视图查询无需调用
table
和join
方法,并且在调用where
和order
方法的时候只需要使用字段名而不需要加表名。
默认使用INNER join查询,如果需要更改,可以使用:
Db::view('User','id,name')
->view('Profile','truename,phone,email','Profile.user_id=User.id','LEFT')
->view('Score','score','Score.user_id=Profile.id','RIGHT')
->where('score','>',80)
->select();
生成的SQL语句类似于:
SELECT User.id,User.name,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User LEFT JOIN think_profile Profile ON Profile.user_id=User.id RIGHT JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80
可以使用别名:
Db::view('User',['id'=>'uid','name'=>'account'])
->view('Profile','truename,phone,email','Profile.user_id=User.id')
->view('Score','score','Score.user_id=Profile.id')
->where('score','>',80)
->select();
生成的SQL语句变成:
SELECT User.id AS uid,User.name AS account,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80
可以使用数组的方式定义表名以及别名,例如:
Db::view(['think_user'=>'member'],['id'=>'uid','name'=>'account'])
->view('Profile','truename,phone,email','Profile.user_id=member.id')
->view('Score','score','Score.user_id=Profile.id')
->where('score','>',80)
->select();
生成的SQL语句变成:
SELECT member.id AS uid,member.name AS account,Profile.truename,Profile.phone,Profile.email,Score.score FROM think
相关文档
- 免费关键词排名优化,关键词排名优化查询
- 网络推广或SEO从业者必看!关键词排名批量查询了解一下?
- 曾经在南京超普及的查询工具——丁丁地图,帮了咱不少忙
- 网站运营必看!alexa排名查询方法及用途全解析?
- 信息爆炸时代常遇陌生事物?快用百度APP或网站查询
- 淘宝关键词查询实用指南,新手速看!3种免费查询工具揭秘
- 丁丁地图查询实用指南:公交地铁步行引导及实时路况全解析
- 淘宝开店必看!如何查询关键词排名及重要性?
- 探秘外链查询工具:作用几何?如何通过它了解网站外部链接情况?
- 如何查看一个网站的收录_百度收录批量查询工具
- 关键词排名工具是啥?能帮上忙吗?查询核心功能模块了解下
- 百度近日收录查询引关注,网站文章何时被收录成难题?
- 查询上海本地出行路线?丁丁地图网这个平台可帮大忙啦
- 关键词排名查询渠道大揭秘!搜索引擎、第三方平台和SEO软件都能查
- 百度排名查询有多重要?关乎流量与曝光率,你知道吗?
- 友链查询工具怎么选?三大避坑指南+实战测评
- 东莞SEO优化实战指南,从基础框架到本地化策略,如何实现排名飞跃
- 小旋风万能蜘蛛池x8.3免权如何实现永久使用?2025最新破解教...
- 北京SEO公司实测:2025未案新站如何实现3小时百度收录?附操...
- 医疗行业网站被降权?蜘池x621城市标签系统如何实现精准权重恢复
上一篇: Eyoucms程序开发:高级查询
下一篇: Eyoucms程序开发:子查询