Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return "0" sales for a kind of subtexture from a left join of results that is null
    primarykey
    data
    text
    <p>DBMS: Derby</p> <p>Language: Java</p> <p>The outer query get the results off the inner query in which it gets the sales of a kind of subtexture within a certain date but sometimes there are no order details for a certain kind of subtexture. So there is nothing to join, I'd like to see a "0" for this kind of situation. Sorry for the bad naming and indentation. Thanks Jack</p> <pre><code>SELECT s1.TextureName AS TYPE, T.month AS MONTH, NULLIF(sum(S.Sales),0) AS NS, NULLIF(T.Total,0) AS total, NULLIF(NULLIF(cast(S.Sales AS Float),0.0) / NULLIF(Cast(T.Total AS float),0.0) * 100.0,0.0) AS percent FROM subtexture s1 LEFT JOIN (SELECT s.SubTextureID, sum(od.NetSales) AS Sales, MONTH(o.PURCHASEDATETIME) AS MONTH FROM subtexture s LEFT JOIN products p ON (s.SubTextureID = p.SubTextureID) LEFT JOIN order_details od ON (p.ProductCode = od.ProductCode) LEFT JOIN orders o ON (od.OrderCode = o.OrderCode) WHERE TRIM(CAST(CAST(YEAR(o.PurchaseDateTime) AS CHAR(4)) AS VARCHAR(4))) || '-' || TRIM(CAST(CAST(MONTH(o.PurchaseDateTime) AS CHAR(2)) AS VARCHAR(2))) = '2013-11' GROUP BY s.SubTextureID, MONTH(o.PurchaseDateTime)) AS S ON (S.SubTextureID = s1.SubTextureID) , (SELECT sum(od.NetSales) AS Total, MONTH(o.PurchaseDateTime) AS MONTH FROM orders o LEFT JOIN order_details od ON (o.OrderCode = od.OrderCode) WHERE TRIM(CAST(CAST(YEAR(o.PurchaseDateTime) AS CHAR(4)) AS VARCHAR(4))) || '-' ||TRIM(CAST(CAST(MONTH(o.PurchaseDateTime) AS CHAR(2)) AS VARCHAR(2))) = '2013-11' GROUP BY MONTH(o.PURCHASEDATETIME)) AS T WHERE T.MONTH = S.MONTH GROUP BY s1.TextureName, T.Total, T.MONTH, S.Sales </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload