Find and display lowest value from one field in a node type I have a Drupal 7 website that tracks values associated with "Content Type A". I have another content type, "Content Type B", which is a part that is associated with Content Type A. Any A item may have one or more B items associated with it:

A-101 (B-201 B-202 B-203)

A-102 (B-301)

Each B item has a field that shows its total number of available uses (its limit, if you will). This is a static integer field. Each A item has a field that shows "aggregated uses" of that item, based on a third content type: "Content Type A-Usage". The "aggregated uses" field in A uses Views and aggregation to add up the A-Usage items referenced/linked to that A item.

I need to take that aggregated A-Usage value and subtract it from the "B-available uses/limit" value, and then display that result in a view or a CCK field.

So let's say A-101 has an aggregated usage of "100", and B-201 has a limit of 500 uses. I need to display the remaining uses for B-201 (400, in this case) in a view or CCK field.

One step further, I also need to take into account the remaining uses for B-201, B-202, and B-203, and pluck the lowest value from those remaining uses and display it in a view/CCK field. Let's say B-201 has 400 remaining uses, B-202 has 350 remaining uses, and B-203 has 100 remaining uses. The view/field in question would simply display "100", as that is the lowest remaining value of those B items.

I'm hoping someone can point me in the right direction, or provide some type of php snippet or guidance to help me accomplish these tasks. Views would be my method of choice, as much of the site's pages are already compiled using Views.

Thanks!
It is not clear from your question if your 'aggregated uses' and 'available uses' are CCK fields already. If they are, I hope this helps... You can access each of the fields available $a and aggregated $b with this code: 

$items = field_get_items('node', $node, 'field_YOUR_FIELDNAME');
$first_item = array_shift($items);
$YOUR_VAR = $first_item['value'];   


then deduct $a-$b=$c and store $c in another CCK field using the node_load and node_save:

 $node = node_load($nid = YOUR_NID);
 $node-&gt;field_YOUR_FIELDNAME[$node-&gt;language] = array(
    0 =&gt; array('value' =&gt; $c)
 );


once $c field is stored in your node, you will be able to access and display it from Views.