1

Hi All and thanks in advance for any help. This is my scenario:

I have three linked tables showing production specs and type of ink used in each. Each spec can have a variable number of inks (from 1 to 10) which may or may not be the same to the others. My objective is for each spec to be able to show the spec name and the ink that appears more frequently.

For example for spec XYZ:

|=====|=====|
¦SPEC ¦INK  ¦
|=====|=====|
¦XYZ  ¦blue ¦
¦XYZ  ¦red  ¦
¦XYZ  ¦red  ¦
¦XYZ  ¦red  ¦
¦XYZ  ¦brown¦
|=====|=====|

I would like to display only:

|=====|=====|
¦SPEC ¦INK  ¦
|=====|=====|
¦XYZ  ¦red  ¦
|=====|=====|

The tables are linked as follows:

SELECT tblStudioInput.SpecNo
    , tblListInkSystem.Ink
FROM tblStudioInput
INNER JOIN tblStudioInputColour
    ON tblStudioInput.stID = tblStudioInputColour.StudioInputID
INNER JOIN tblListInkSystem
    ON tblStudioInputColour.InkSystem = tblListInkSystem.ID

Again thanks in advance to everybody

4

2 に答える 2

2
SELECT SPEC, INK
FROM
  (
    SELECT SPEC, INK,
           DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) rn
    FROM Table1
    GROUP BY SPEC, INK
  ) s
WHERE rn = 1

ソース

于 2012-11-22T00:15:31.373 に答える