1

I want to convert following sql query to zend query. How I can convert this mysql query into zend query with zend framework 2?

SELECT SUM(amount)
FROM tbl_sale_amount 
WHERE sale_type_id=7459650 AND YEAR(db_add_date) = YEAR(CURDATE()); 

NOTE: Need to fetch sum of amount for current year from tbl_sale_amount.

Thanks

GOT MY ANSWER HERE: ZF2 Query WHERE clause with DATE() for datetime column

1

1 Answer 1

0

Use this

 $stmt = $db->query('SELECT SUM(amount)
    FROM tbl_sale_amount 
    WHERE sale_type_id= ? AND YEAR(db_add_date) = YEAR(CURDATE()',
                array($sale_type_id)
            );

$result = $stmt->fetchAll();
        $stmt->closeCursor();
        if ($result) {
            return $result;
        } else {
            return false;
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.