这个问题听起来可能有些混乱,我会尽力进行解释。我有4张桌子:
目标是从import * as updater from './updater';
import { repeatMe } from './code';
test('repeatMe', async () => {
jest.useFakeTimers();
let doAsyncStuff = jest.spyOn(updater, 'doAsyncStuff');
doAsyncStuff.mockResolvedValue(true);
repeatMe();
jest.advanceTimersByTime(5000);
expect(doAsyncStuff).toHaveBeenCalledTimes(1); // Success!
await Promise.resolve(); // let callbacks in PromiseJobs run
jest.advanceTimersByTime(5000);
expect(doAsyncStuff).toHaveBeenCalledTimes(2); // Success!
await Promise.resolve(); // let callbacks in PromiseJobs run
jest.advanceTimersByTime(5000);
expect(doAsyncStuff).toHaveBeenCalledTimes(3); // Success!
// ... and so on ...
});
表中获取特定产品的所有{strong> ,只要id
不是 链接到当前的store_item_stock
以下是结构的SQLfiddle:my answer here
我当前的查询实际上获取了产品的所有store_item_stock.id_attribute
行,但是它还包括属于当前store_item.id_cat
的属性:
store_item_stock
例如,store_item.id_cat
2、3和4属于SELECT store_item_stock.id, store_item_stock.id_attribute, store_item_stock.stock
FROM store_item_stock
LEFT JOIN store_item ON store_item.id_item = store_item_stock.id_item
LEFT JOIN store_cat_attribute ON store_cat_attribute.id_cat = store_item.id_cat
WHERE store_item_stock.id_item = 1 AND store_item.id_cat = 2 GROUP BY store_item_stock.id
2,而id_attribute
33和34属于id_cat
4,因此如果查询的目的是获取所有id_attribute
行,除了将id_cat
链接到store_item_stock
2的行之外,应返回:
答案 0 :(得分:1)
SELECT store_item_stock.id, store_item_stock.id_attribute, store_item_stock.stock
FROM store_item_stock
JOIN store_cat_attribute
ON store_item_stock.id_attribute=store_cat_attribute.id_attribute
WHERE id_cat NOT IN (
SELECT store_item.id_cat
FROM store_item JOIN store_cat_attribute
ON store_item.id_cat=store_cat_attribute.id_cat
WHERE store_item.id_cat=2
GROUP BY store_item.id_cat);
我想这不是那么简单,但是让我们尝试一下,看看条件是否符合您想要的输出。