Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 无法选择左联接之外的列_Sql - Fatal编程技术网

Sql 无法选择左联接之外的列

Sql 无法选择左联接之外的列,sql,Sql,我正在处理以下查询 SELECT * FROM (SELECT DISTINCT a.Number ,a.Description ,ISNULL(temp.Quantity,0) Quantity ,LastReceived ,LastIssued FROM Article a

我正在处理以下查询

SELECT * FROM 
        (SELECT DISTINCT 
                 a.Number
                ,a.Description
                ,ISNULL(temp.Quantity,0) Quantity
                ,LastReceived
                ,LastIssued
                FROM Article a
                LEFT JOIN (
                        select  ss.ArticleId
                                , ss.Quantity 
                                , max(lastreceiveddate) as LastReceived
                                , max(lastissueddate) as LastIssued
                        from StockSummary ss
                        where ss.UnitId = 8
                        group by ss.ArticleId, ss.StockQuantity
                        having (MAX(ss.LastReceivedDate) < '2014-09-01' or MAX(ss.LastReceivedDate) is NULL)
                                AND (MAX(ss.LastIssuedDate) < '2014-09-01' or MAX(ss.LastIssuedDate) is NULL)
                        ) temp on a.Id = temp.ArticleId
        WHERE a.UnitId = 8 
        ) main
ORDER BY main.Number
我想要实现的是在左连接查询中仅选择具有MAXss.LastReceivedDate和MAXss.LastIssuedDate条件的文章,然后在主查询中进行数量选择。 注意:数量列可以是0或NULL。
请帮忙

您的专栏是“库存数量”还是“数量”?您确定查询中使用的所有列都存在于同名的相应表中吗?这有什么问题吗?你能展示一些样本数据和你想要得到的结果吗?对不起,列名是quantity。不是库存数量您使用的是哪种数据库管理系统?博士后?甲骨文?对迟来的回复表示歉意。但我找到了解决方案,在库存汇总表的左连接之后,我再次进行了内部连接,以获取数量。