Laravel Query Builder组通过结合关系

考虑这两个具有一对多关系的简单表:

汽车

  • id
  • 品牌
  • user_id

用户

  • id
  • 用户名

用户可以拥有多辆汽车,每辆汽车都属于一个用户。

对于每个汽车品牌,我想知道拥有大多数汽车品牌的用户名+金额。

使用一个SQL查询是否可能?我正在寻找使用Laravel Query Builder的最优雅的方法吗?

DB::table('cars')->groupBy('brand');

这是我到目前为止所拥有的...

谢谢!

adaci 回答:Laravel Query Builder组通过结合关系

希望这会有所帮助。

#!/usr/bin/python3.6

exc = 'foofoo'
print('exc in locals?','exc' in locals())
try:
  x = 1 / 0
except Exception as exc_:
  exc = str(exc_)
  print('exc in locals?','exc' in locals())
  print('Error,exc)
print('exc in locals?','exc' in locals())
print('Sorry,got an exception',exc)
,

尝试

func / <F: BinaryFloatingPoint,I: BinaryInteger>(lhs: F,rhs: I) -> F {
    return lhs / F(rhs)
}
func / <F: BinaryFloatingPoint,I: BinaryInteger>(lhs: I,rhs: F) -> F {
    return rhs / F(lhs)
}

let a = 10.0
let b: UInt8 = 8

print(a/b) //outputs 1.25
print(b/a) //THIS is where weird stuff shows because it outputs 1.25 as well,but should 0.8!!
本文链接:https://www.f2er.com/3134914.html

大家都在问