Mysql 嵌套SQL查询?
我有两张这样的桌子:Mysql 嵌套SQL查询?,mysql,sql,google-bigquery,Mysql,Sql,Google Bigquery,我有两张这样的桌子: product_table[ product_id, product_name,original_store_id, destination_store id] 及 我想找到的是:从所有那些发货到没有成立日期的商店的产品中,有多少是从有成立日期的商店发货的 这是我的疑问: SELECT count(a.product_id) as count_of_products FROM product_table a JOIN store_table b ON a.original
product_table[ product_id, product_name,original_store_id, destination_store id]
及
我想找到的是:从所有那些发货到没有成立日期的商店的产品中,有多少是从有成立日期的商店发货的
这是我的疑问:
SELECT count(a.product_id) as count_of_products
FROM product_table a
JOIN store_table b
ON a.original_store_id = b.store_id AND a.destination_store_id = b.store_id
WHERE b.establishment_date IS NULL
我知道这应该是一个嵌套查询,但我如何将它们放在这里?您可以尝试向
store\u表添加第二个联接,以进一步限制仅从具有成立日期的商店发货的产品:
SELECT COUNT(a.product_id) AS count_of_products
FROM product_table a
INNER JOIN store_table b
ON a.destination_store_id = b.store_id
INNER JOIN store_table c
ON a.original_store_id = c.store_id
WHERE
b.establishment_date IS NULL AND
c.establishment_date IS NOT NULL;
您可以尝试将第二个联接添加到store\u表
以进一步限制仅从具有成立日期的商店发货的产品:
SELECT COUNT(a.product_id) AS count_of_products
FROM product_table a
INNER JOIN store_table b
ON a.destination_store_id = b.store_id
INNER JOIN store_table c
ON a.original_store_id = c.store_id
WHERE
b.establishment_date IS NULL AND
c.establishment_date IS NOT NULL;
. . 使用有意义的表格别名,而不是毫无意义的字母。使用有意义的表别名,而不是无意义的字母。