简体   繁体   English

SQL加入Rails

[英]SQL Joins In Rails

User.where(created_at: "2015-08-02").joins(:likes).count

What does this exactly mean in Rails? 这在Rails中到底意味着什么? Specifically compared to User.where(created_at: "2015-08-02").count (without joins) 专门与User.where(created_at: "2015-08-02").count (不包含联接)进行比较

Please translate it to English. 请翻译成英文。 Thanks. 谢谢。

the first one joined 2 tables ( likes and users ) and count the entries in the users table which have an entry in the likes table. 第一个加入了2个表(“ likes和“ users ),并计算“ users表中的条目,这些条目在“ likes表中具有条目。 the other one count all users and don't care about entries in the likes table 另一个计算所有users ,不关心点likes表中的条目

so if you have 100 users, then both gives you count 100. if you have 100 users, and 90 users have a like, then your first gives you ccount of 90 and your second query gives you count of 100. 因此,如果您有100个用户,那么两个都给您计数100。如果您有100个用户,而90个用户有个赞,那么您的第一个给您的计数为90,第二个查询给您的计数为100。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM