The issue with checking for the
Count tag is that it checks for an exact match rather than minimum. The player must have a stack of exactly 2 emeralds in a slot in their inventory, otherwise they cannot match.
To circumvent that, you will have to use CommandStats, which are a set of triggers that can set a target's scoreboard score based on the success of the command. For example, the "SuccessCount" trigger sets a score equal to the number of times a command was successfully processed (such as
/testfor @e[type=Creeper] resulting in a score equal to the number of creepers).
For item detection, "AffectedItems" will be used.
Objective to hold each player's "AffectedItems" return value.
/scoreboard objectives add ITEMS dummy
In order for CommandStats to modify a target's score, that target must be tracked prior. This may need to run on a clock in the event new players can join at any time.
/scoreboard players add @a ITEMS 0
The following will need to be run on a clock.
CommandStat trigger applied to all players, who will set their own "ITEMS" score based on commands that they run. This needs to run on a clock because it is being removed during detection.
/stats entity @a set AffectedItems @a[c=1] ITEMS
The following must be run in numerical order each time you want the player to sell an item. You may need to change target selectors to target a specific player, such as using x/y/z/r parameters depending on your setup.
Cause players to use
/clear to remove 0 of the specified item. While this does not remove any items, the stored "AffectedItems" trigger will receive the number of items that could have been cleared, which would be equal to the number of emeralds across the player's inventory. Their "ITEMS" score will be set to that number.
/execute @p[x=0,y=0,z=0,r=0] ~ ~ ~ /clear @a[c=1] minecraft:emerald 0 0
If a player had at least 16 emeralds ("ITEMS" score of 16+), then remove their "AffectedItems" trigger to preserve their score. If a
/clear command is used instead, their "ITEMS" score will be modified and thus can no longer reliably be used.
/stats entity @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] clear AffectedItems
Provide the player with necessary item if they have an "ITEMS" score of 16+, which means they have 16+ emeralds.
/give @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] minecraft:stone
Remove the 16 emeralds from the player's inventory.
/clear @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] minecraft:emerald 0 16
You will repeat the "Detection" command set for each item you want to sell. Make sure to change the coordinates for each section.
General info on commands.