我有一个作业问题,我遇到了麻烦。我被要求查询我们数据库中从未出售过的产品总数。
它应该看起来像这样:
+--------------------------------------------+
| number of products that have not been sold |
+--------------------------------------------+
| 228 |
+--------------------------------------------+
我不断得到这个:
+--------------------------------------------+
| number of products that have not been sold |
+--------------------------------------------+
| 0 |
+--------------------------------------------+
我的查询是:
SELECT count(*) AS 'number of products that have not been sold'
FROM orderdetail
JOIN invoice on invoice.invoiceid=orderdetail.invoiceid
WHERE productid is null;
答案 0 :(得分:2)
product
表必须是加入中的起始表。orderDetail
加入ProductID
表COUNT()
函数尝试以下操作:
SELECT count(p.ProductID) AS 'number of products that have not been sold'
FROM product AS p
LEFT JOIN orderDetail AS od ON od.ProductID = p.ProductID
WHERE od.productid IS NULL
答案 1 :(得分:0)
您可以尝试以下方法:在产品上使用leftjoin而不是orderdetail:
def printType[T](input: String)(implicit tag: TypeTag[T]): Option[T] = {
val t = typeOf[T]
println(s"$t")
...
}
def foo: Int = {
printType[Int]("something") // prints Int
}
def bar: Int = {
printType("something") // prints Nothing
}