data table test
has the following data
{name: "a", parent_key: 1,value: 11},
{name: "b", parent_key: 3,value: 12},
{name: "c", parent_key: 3,value: 13},
{name: "d", parent_key: 3,value: 14},
{name: "e", parent_key: 2,value: 15},
{name: "f", parent_key: 1,value: 16}
use the SQL statement SELECT COUNT (name) FROM test WHERE parent_key in (1) GROUP BY parent_key; 2 3) GROUP BY parent_key; 4 5
in this way, values with parent_key of 4 and 5 are automatically ignored.
now I want to count all the count, of parent_key. If not, return 0, that is,
{parent_key: 1, count: 2},
{parent_key: 2, count: 1},
{parent_key: 3, count: 3},
{parent_key: 4, count: 0},
{parent_key: 5, count: 0},
in addition to finding the results and then assembling the results, can you directly use SQL statements to achieve it?