XPath help: Find element with most occurrences

S

STA

Hi.

Given this XML:
<itemdata>
<item>
<itemid>10</itemid>
<ctid>1</ctid>
</item>
<item>
<itemid>11</itemid>
<ctid>2</ctid>
</item>
<item>
<itemid>12</itemid>
<ctid>3</ctid>
</item>
<item>
<itemid>13</itemid>
<ctid>3</ctid>
</item>
<item>
<itemid>14</itemid>
<ctid>3</ctid>
</item>
<item>
<itemid>15</itemid>
<ctid>4</ctid>
</item>
<item>
<itemid>16</itemid>
<ctid>4</ctid>
</item>
</itemdata>

How can I find the ctid that occurs the most times? In this sample, I'm
looking for a result of "3", because there are 3 items where ctid=3,
and the next closest (4) only has 2 occurrences.

Thanks in advance for any help.
STA
 
J

Joe Kesselman

STA said:
How can I find the ctid that occurs the most times?

Just a SWAG, but: I'd suggest approaching this as a combination of a
grouping problem (find the items with the same ctid) and a sorting
problem (pick the longest group(s)).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top