Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL – Split SELECT query (WHERE IN) into two rows

So, I am using MySQL to do a query and have a database like this:

Tables

I wanted to do a select query to show every transaction of Bank A and C based on their prefix. This is the expected result:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Expected Result

I have done the query as followed:

SELECT
    M.merk AS 'Merk',
    COUNT( T.amount ) AS 'Jumlah Transaksi',
    SUM( T.amount ) AS 'Total Amount'
FROM
    tb_transaksiatm T
INNER JOIN tb_issuer I ON
    T.nomor_kartu LIKE CONCAT(I.prefix, '%')
INNER JOIN tb_terminalatm M ON
    T.terminal = M.nomor_terminal
WHERE
    I.bank IN ('A', 'C') # Declare the Bank;

But my result is not the same as expected. It combined and summed both rows from Bank A and Bank C. This is my result:

Result

The question is, how do I split the WHERE IN condition into two rows? Any help would be appreciated. Thank you.
Note: The language is Indonesian.

>Solution :

SELECT
    M.merk AS 'Merk',
    COUNT( T.amount ) AS 'Jumlah Transaksi',
    SUM( T.amount ) AS 'Total Amount'
FROM
    tb_transaksiatm T
INNER JOIN tb_issuer I ON
    T.nomor_kartu LIKE CONCAT(I.prefix, '%')
INNER JOIN tb_terminalatm M ON
    T.terminal = M.nomor_terminal
WHERE
    I.bank IN ('A', 'C') # Declare the Bank
group by M.merk;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading