mysql sum with if
SELECT SUM(IF( `column` = 1, `column`, 0)) as total
mysql sum with if
SELECT SUM(IF( `column` = 1, `column`, 0)) as total
using sum function in mysql for two diffrenet conditions
SELECT
SUM(CASE
WHEN status = 'Shipped' THEN quantityOrdered
END) qty_shipped,
SUM(CASE
WHEN status = 'Resolved' THEN quantityOrdered
END) qty_resolved,
SUM(CASE
WHEN status = 'Cancelled' THEN quantityOrdered
END) qty_cancelled,
SUM(CASE
WHEN status = 'On Hold' THEN quantityOrdered
END) qty_on_hold,
SUM(CASE
WHEN status = 'Disputed' THEN quantityOrdered
END) qty_on_disputed,
SUM(CASE
WHEN status = 'In Process' THEN quantityOrdered
END) qty_in_process
FROM
orderdetails
INNER JOIN
orders USING (orderNumber);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us