【发布时间】:2018-06-10 13:00:51
【问题描述】:
我有以下2 tables involved,我正在尝试create a view popularProducts,其中sum of each product's quantityOrdered 等于或高于100。
我尝试了以下方法,但对我来说并不完全正确:
SELECT productCode, productName, buyPrice, image FROM products JOIN orderDetails on products.productCode=orderDetails.products_productCode WHERE (SELECT SUM(quantityOrdered) >= 100);
OrderDetails表:
CREATE TABLE `orderDetails` (
`products_productCode` bigint(20) UNSIGNED NOT NULL,
`orders_orderNumber` bigint(20) UNSIGNED NOT NULL,
`quantityOrdered` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
还有products表:
CREATE TABLE `products` (
`productCode` bigint(20) UNSIGNED NOT NULL,
`productName` varchar(45) DEFAULT NULL,
`productDescription` text,
`quantityInStock` smallint(5) UNSIGNED DEFAULT NULL,
`buyPrice` decimal(7,2) UNSIGNED DEFAULT NULL,
`image` varchar(45) DEFAULT NULL
) E
【问题讨论】: