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软件都能查
- 百度排名查询有多重要?关乎流量与曝光率,你知道吗?
- 友链查询工具怎么选?三大避坑指南+实战测评
- 东莞SEO优化实战指南,从基础框架到本地化策略,如何实现排名飞跃
- 小旋风万能蜘蛛池x8.3免权如何实现永久使用?2025最新破解教...
- 北京SEO公司实测:2025未案新站如何实现3小时百度收录?附操...
- 医疗行业网站被降权?蜘池x621城市标签系统如何实现精准权重恢复
- 2025年小旋风万能蜘蛛池ro采集如何实现搜狗秒收?【实战案例解...
- 2025年如何通过老域名和度站长工具实现域名快速收录?
- 2025年如何实现秒收录秒名?最新SEO技术全解析
- (新手必看)百度指数查询程:5分钟掌握数据采集技巧
- SEO查询到底要花多少钱才不算被坑?
- 网站seo查询,网站seo在线检测
- 网站权重seo,网站权重综合排名查询方法
- 谷歌关键词排名查询工具
- 在哪里查询网站的关键词排名,怎么查网站关键词排名情况
- 如何通过“ChatGPT行程签证”轻松实现全球旅行梦想
- pbootcms模板修改tags实现keywords内容关联匹配
- 如何在PbootCMS中实现无刷新点赞功能?
- PbootCMS实现数字条分页样式效果
上一篇: Eyoucms程序开发:高级查询
下一篇: Eyoucms程序开发:子查询