I am trying to create the query with UNION where I have two same tables but the condition in both tables are different. I am getting output as below structure
SELECT
`u`.`inward`,
`u`.`outward`
FROM
(
SELECT
COALESCE(SUM(`qty`),
0) AS `inward`
FROM
`table_1`
WHERE
`col_name` = '321' AND (
`transaction_type` = 'SALES' OR `transaction_type` = 'ISSUE'
) AND `col_id` = '123'
UNION
SELECT
COALESCE(SUM(`qty`),
0) AS `outward`
FROM
`table_1`
WHERE
`col_name` = '321' AND (
`transaction_type` = 'PURCHASE' OR `trans_type` = 'ISSUE'
) AND `col_id` = '123'
) u
Please help to get the expected output in your suggested methods
SELECT
CASE WHEN transaction_type = 'PURCHASE' THEN COALESCE(SUM(`qty`), 0) ELSE 0 END AS `inward`
CASE WHEN transaction_type = 'SALES' THEN COALESCE(SUM(`qty`), 0) ELSE 0 END AS `outward`
FROM
`table_1`
WHERE
`col_name` = '321' AND (
(`transaction_type` = 'PURCHASE' OR transaction_type = 'SALES' OR `trans_type` = 'ISSUE'
) AND `col_id` = '123'
SELECT SUM(CASE WHEN transaction_type IN ( 'ISSUE','SALES' )
THEN qty
ELSE 0 END ) AS inward
, SUM(CASE WHEN transaction_type IN ( 'ISSUE','PURCHASE' )
THEN qty
ELSE 0 END ) AS outward
FROM table_1
WHERE col_name = '321'
AND col_id = '123'
AND transaction_type IN ( 'ISSUE','SALES','PURCHASE' )
As you’ve probably realised, late August 2014 was when members were imported from vBulletin to Discourse. Large numbers of members have join dates of 29th and 30th.
The only folk with earlier join dates are members who were staff at the time of the move, and had been testing Discourse prior to the migration. e.g.:
It’s a shame we couldn’t import original join dates, but apparently that wasn’t possible.