I’m not sure if I should be using Sub-selects or not.
Here is some sample data:
Eg. Report Table with Data
-----------------------------
id BusID Date Link Det Click
1 32 2011-12-19 0 0 1
2 34 2011-12-21 0 1 0
3 32 2011-12-22 1 0 0
3 32 2011-12-22 1 0 0
4 33 2011-12-23 1 0 0
5 32 2011-12-23 0 0 1
4 33 2011-12-23 1 0 0
5 32 2012-01-05 0 0 1
3 32 2012-01-06 1 0 0
4 33 2012-01-06 1 0 0
5 32 2012-01-08 0 0 1
business Table with Data
-----------------------------
id name
32 Acme Inc
33 Orange Computers
34 OHBHL Corp
What I am looking for is a query to list like the following:
DECEMBER 2011
-------------
Acme Inc. Linked: 5 Det: 3 Clicked: 3
Orange Linked: 3 Det: 4 Clicked: 4
… and so forth for each month/year
use
SUM(link),SUM(det),SUM(clicked)andGROUP BYdate truncate to month and id, name.