Hi,
There are many interesting "limits", like
SELECT (Option='A'), (Option='B'), ... , COUNT(*)
FROM
GROUP BY (Option='A'), (Option='B'), ...
but the SELECT is limited to 255 fields, and the GROUP BY to 32, I think,
Another solution would be based on a LIST concatenation, to build 'ABCD', a
string of selected option, but now, such a string, a varchar is limited to
255 characters, too! No good.
So I decide to take a different approach, a "relational" one.
===============
SELECT a.CarID As thisCar, b.CarID As thatCar
FROM myTable As a INNER JOIN myTable As b
ON a.option = b.option
GROUP BY a.carID, b.carID
HAVING COUNT(*) = (SELECT COUNT(*) FROM myTable As c
WHERE c.carID=a.carID)
AND COUNT(*) = (SELECT COUNT(*) FROM myTable As d
WHERE d.carID = b.carID)
================
seems, at first glance (***not tested***) to associate together cars having
exactly all the same options. The association is indirect, it is a list, two
by two, like:
thisCar thatCar
-----------------------
car1 car1
car1 car3
car1 car4
car2 car2
car3 car1
car3 car3
car3 car4
car4 car1
car4 car3
car4 car4
which would tell us that car1 has the same options than car1, car3, and
car4.
Save that query, Qs, then
SELECT thisCar, COUNT(*)
FROM qs
GROUP BY thisCar
tell us how popular are the options of each car.
car1 3
car2 1
car3 3
car4 3
so, as example the combo of options on car1 is exactly the same on two other
cars ( 3 with itself). We then know which CAR have the most popular "set"
of options, or combo as you said.
A problem is to eliminate "symmetry", that is, if car1 has the same options
than N other cars, then N other records would say exactly the same thing.
That is not good, for stats neither for presentation. We have to eliminate
those N other cars. We don't have their options, but the following should
do:
==============
SELECT w.thisCar, COUNT(*)
FROM qs As w
WHERE thisCar <= ALL (SELECT z.thatCar
FROM qs As z
WHERE z.thisCar = w.thisCar)
GROUP BY w.thisCar
===============
Note that someone can replace
<= ALL( SELECT z.thatCar FROM ...
with
= (SELECT MIN(z.thatCar) FROM ...
here, since there is no NULL implies.
Indeed, it is based on that if we have
car4 car1
car4 car3
car4 car4
then, it fails the test car4 = MIN(car1, car3, car4), and only one car of
the "group of car with the same combo", should ever satisfy the test.
So, that last query, qs2, give us the popularity of a combo of options, you
can add an ORDER BY on the COUNT, and a representative car having this combo
of options (BUT does not list the said options, part of the "combo"). Thanks
to relationship based solution, we almost completely evacuate the need to
deal with the options themselves. It is a little bit as if we "borrowed" a
carID to make it a "combo id". We do that every day in speech, so, why not
in our SQL
Since you have a representative carID, you can get the
individual options in this "combo", through a join with table2.
Is that close enough to what you want?
Hoping it may help,
Vanderghast, Access MVP