Home:ALL Converter>How can I write the query bellow efficiently and cleaner?

How can I write the query bellow efficiently and cleaner?

Ask Time:2018-06-08T22:02:43         Author:user4148098

Json Formatter

First, I am selecting from two different databases, db1 and db2. From each database. On db1, I am counting results based on a condition from one column based on the data in that column. Same applies for db2.

    SELECT 
    (SELECT COUNT(*) FROM db1.table1) AS Column1,
    (SELECT COUNT(*) FROM db1.table1 where  
                          table1.X ='a') AS Column2,
    (SELECT COUNT(*) FROM db1.table1 where  
                         table1.X = 'b') AS Column3,
    (SELECT COUNT(*) FROM db1.table1 where 
                         table1.X = 'c') AS Column4,
    (SELECT COUNT(*) FROM db1.table1 where 
                          table1.X = 'd') AS Column5,
    (SELECT COUNT(*) FROM db1.table1 where
                          table1.X = 'e') AS Column6,
    (SELECT COUNT(*) FROM db2.table2 where
                          table2.Y = 'f') AS Column7,
    (SELECT COUNT(*) FROM db2.table2 where
                          table2.Y = 'g') AS Column8,
    (SELECT COUNT(*) FROM db2.table2 where
                          table2.Y = 'h') AS Column9,
    (SELECT COUNT(*) FROM db2.table2 where
                          table2.Y = 'i') AS Column10;

Author:user4148098,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762397/how-can-i-write-the-query-bellow-efficiently-and-cleaner
yy