jeudi 6 septembre 2018

eloquent query for getting difference of two columns from different table

I've to show the remaining quantity of books using eloquent query. I can get total number of purchased books from this table

ordered_books
BOOKCODE[varchar(10)]   QUNATITY[varchar(6)]
111                         25
423                         15
201                         10
111                         10
423                         10
201                         5
158                         12

At first I've to sum the total books for each of the book code. Then from the another table I've to calculate the difference.

books_out
DISTRIBUTOR[varchar(50)]    BOOKCODE[varchar(10)]           QUNATITY[varchar(6)]    
25                              158                             2
35                              201                             5
45                              158                             5
55                              111                             10
35                              111                             5
15                              423                             1
25                              423                             10

Again, from this table I've to calculate the total number of books taken by distributors then I can get the actual number of books present. How shall I write eloquent query for this scenario?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire