Skip to content

Commit

Permalink
[#24] fix: sales log가 없을 때도 상품 목록 출력하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chung committed Jun 29, 2023
1 parent 2aa1a76 commit f508d98
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public ProductRepository(final DataSource dataSource) {
}

public List<Product> findProductsBy(final String category) {
String sql = "SELECT p.*, SUM(sl.count) total_quantity"
+ " FROM product p"
+ " JOIN category c ON p.category_id = c.id"
+ " JOIN sales_log sl ON p.id = sl.product_id"
+ " WHERE c.name = :name"
+ " AND DATE(sl.sales_at) = CURDATE()"
+ " GROUP BY p.id"
+ " ORDER BY total_quantity desc";
String sql = "SELECT p.*, SUM(sl.count) as total_quantity " +
"FROM product p " +
" JOIN category c ON p.category_id = c.id " +
" LEFT JOIN sales_log sl ON p.id = sl.product_id AND DATE(sl.sales_at) = CURDATE() " +
"WHERE c.name = :name " +
"GROUP BY p.id " +
"ORDER BY total_quantity desc";

SqlParameterSource params = new MapSqlParameterSource("name", category);

Expand Down

0 comments on commit f508d98

Please sign in to comment.