Domanda

I have 2 database tables, innov8_data & innov8_data_fps.

innov8_data is my master table, innov8_data_fps is populated once a day new data from a import script.

What I need to do is identify differences in innov8_data from the new data imported to innov8_data_fps.

my data structure is id, sku, free_stock for both tables.

First 3 rows of innov8_data;

1,08-143800-00,0
2,DC83406,8
3,HBS106,0

Now if the first 3 rows of innov8_data_fps are as follows;

1,08-143800-00,0
2,DC83406,8
3,HBS106,8

I need to be able to identify the changes to the free_stock column for items with the same sku. The id column isn't consistent with the same product in each as the new import can have more or less sku's.

È stato utile?

Soluzione 3

I have managed to modify the code SQL statement posted earlier and now have it working as I wanted, thanks for your help.

SELECT t1.*,
t1.free_stock <> t.free_stock  `changes`
FROM innov8_data t
JOIN innov8_data_fps t1
  ON(t.sku = t1.sku)
WHERE t1.free_stock <> t.free_stock

Altri suggerimenti

You can do so

SELECT t.*,
t1.free_stock - t.free_stock  `changes`
FROM innov8_data t
JOIN innov8_data_fps t1
  ON(t.sku = t1.sku)

Demo

The previous answer basically nails it, except for not filtering out results where 'changes' = 0. If that's desired, I suggest this enhancement:

SELECT t.*,
t1.free_stock - t.free_stock  `changes`
FROM innov8_data t
JOIN innov8_data_fps t1
  ON(t.sku = t1.sku)
WHERE t1.freestock - t.free_stock != 0;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top