From what I can tell, the queries from perennate, Flapadar, and the last one listed by KuJoe are all basically the same.
perennate:
SELECT tblservers.name, tblproducts.name, COUNT(*)
FROM tblservers, tblhosting, tblproducts
WHERE tblhosting.server = tblservers.id
AND tblhosting.packageid = tblproducts.id
AND YEAR(tblhosting.regdate) = YEAR(CURDATE())
AND MONTH(tblhosting.regdate) = MONTH(CURDATE())
AND tblhosting.domainstatus = 'Active'
AND tblservers.disabled = 0
GROUP BY tblservers.id, tblproducts.id;
KuJoe:
SELECT tblproducts.name, COUNT(*), tblservers.name
FROM tblservers, tblhosting, tblproducts
WHERE tblhosting.server = tblservers.id
AND tblhosting.packageid = tblproducts.id
AND YEAR(tblhosting.regdate) = YEAR(CURDATE())
AND MONTH(tblhosting.regdate) = MONTH(CURDATE())
AND tblhosting.domainstatus = 'Active'
AND tblservers.disabled = 0
GROUP BY tblservers.id, tblproducts.id;
Flapadar (with WHERE clause added and a few naming corrections):
SELECT P.NAME , COUNT(*) , S.name
FROM tblproducts P
INNER JOIN tblhosting H ON H.packageid = P.id
INNER JOIN tblservers S ON H.server = S.id
WHERE YEAR(H.regdate) = YEAR(CURDATE())
AND MONTH(H.regdate) = MONTH(CURDATE())
AND H.domainstatus = 'Active'
AND S.disabled = 0
GROUP BY S.id , P.id;
I created these test tables and sample data from what I could gather from your post.
create table tblservers (id int, name varchar(255), disabled int);
insert into tblservers (id, name, disabled) values (1, 'server01', 0);
insert into tblservers (id, name, disabled) values (2, 'server02', 0);
insert into tblservers (id, name, disabled) values (3, 'server03', 1);
insert into tblservers (id, name, disabled) values (4, 'server04', 0);
create table tblproducts (id int, name varchar(255));
insert into tblproducts (id, name) values (1, 'ovz01');
insert into tblproducts (id, name) values (2, 'ovz02');
create table tblhosting (server int, packageid int, regdate date, domainstatus varchar(32));
insert into tblhosting (server, packageid, regdate, domainstatus) values (1, 1, '2014-07-01', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (1, 1, '2014-07-02', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 1, '2014-07-03', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 1, '2014-07-04', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 1, '2014-07-04', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 1, '2014-07-04', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 2, '2014-07-04', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (2, 2, '2014-07-04', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (3, 1, '2014-07-05', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (3, 1, '2014-07-06', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (3, 2, '2014-07-07', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (4, 1, '2014-07-08', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (4, 1, '2014-07-09', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (4, 2, '2014-07-10', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (4, 2, '2014-07-11', 'Active');
insert into tblhosting (server, packageid, regdate, domainstatus) values (4, 2, '2014-07-12', 'Inactive');
Code:
mysql> desc tblservers;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(255) | YES | | NULL | |
| disabled | int(11) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> desc tblproducts;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> desc tblhosting;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| server | int(11) | YES | | NULL | |
| packageid | int(11) | YES | | NULL | |
| regdate | date | YES | | NULL | |
| domainstatus | varchar(32) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
When I run the 3 queries, I get essentially the same results:
perennate:
+----------+-------+----------+
| name | name | COUNT(*) |
+----------+-------+----------+
| server01 | ovz01 | 2 |
| server02 | ovz01 | 4 |
| server02 | ovz02 | 2 |
| server04 | ovz01 | 2 |
| server04 | ovz02 | 2 |
+----------+-------+----------+
5 rows in set (0.01 sec)
KuJoe:
+-------+----------+----------+
| name | COUNT(*) | name |
+-------+----------+----------+
| ovz01 | 2 | server01 |
| ovz01 | 4 | server02 |
| ovz02 | 2 | server02 |
| ovz01 | 2 | server04 |
| ovz02 | 2 | server04 |
+-------+----------+----------+
5 rows in set (0.00 sec)
Flapadar:
+-------+----------+----------+
| NAME | COUNT(*) | name |
+-------+----------+----------+
| ovz01 | 2 | server01 |
| ovz01 | 4 | server02 |
| ovz02 | 2 | server02 |
| ovz01 | 2 | server04 |
| ovz02 | 2 | server04 |
+-------+----------+----------+
5 rows in set (0.00 sec)
It's possible that I've got the schema or table relationships wrong, though, so something different may be needed in that case.