有没有办法用条件计算相关列并添加到主对象中。 我有架构表,如:
-Book
-Author
-Reader
我查询如下:
$readerQuery
->joinWith('book')
->useBookQuery()
->joinWith('author')
->endUse()
->withColumn('COUNT(Author.Id)', 'readBook')
->withColumn('COUNT(Author.Name)', 'bookByAuthorName(foo)')
->withColumn('COUNT(Author.Name)', 'bookByAuthorName(bar)')
->find()
我想要的结果如下:
id name readBooks bookByAuthorName(foo) bookByAuthorName(bar)
1 john 4 2 2
2 doe 6 4 2
注意:想象一下这里最简单的关系,它不是实际问题