2013-08-02 77 views
1

我有一個表[tblFull1 04WoodsideTransportV335],所有的數據來自。我想獲得壓力爲Max,Min或Abs的[Data Location]和[load_case]。它適用於Max和Min。 但由於某些原因,它不適用於Abs。它在ms Access 2013中運行。我使用vba以編程方式生成查詢。爲什麼我的sql在使用Max函數時不能與Abs函數一起工作?

Abs和max,min運算符之間是否有任何區別,使得它不起作用?

當Abs查詢運行時,由於某種原因,它將「As Expr1」廣告,爲什麼會這樣做?

我知道SQL看起來不好,但它的工作原理。如果您對如何改進建議有任何建議,請告訴我。

對不起,我英語不好,我是挪威語。

SQL與MAX功能:

SELECT DISTINCT 
    t1.[load_case], t2.[Data Location] AS Nodenr, 
    t2.[MaxOfHoop Stress N/mm^2] 
FROM 
    [tblFull1 04WoodsideTransportV335] AS t1, 
    (SELECT 
     [tblFull1 04WoodsideTransportV335].[Data Location], 
     MAX([tblFull1 04WoodsideTransportV335].[Hoop Stress N/mm^2]) AS [MaxOfHoop Stress N/mm^2] 
    FROM 
     [tblFull1 04WoodsideTransportV335] 
    GROUP BY 
     [tblFull1 04WoodsideTransportV335].[Data Location] 
    HAVING ((([tblFull1 04WoodsideTransportV335].[Data Location]) 
     In (SELECT [Data Location] 
      FROM [tblFull1 04WoodsideTransportV335] 
      GROUP BY [Data Location] 
      HAVING Count(*) > 1)) 
     AND ((MAX([tblFull1 04WoodsideTransportV335].[Hoop Stress N/mm^2])) Is Not Null)) 
    ORDER BY 
     [tblFull1 04WoodsideTransportV335].[Data Location]) AS t2 
WHERE 
    ((t1.[Hoop Stress N/mm^2]) = [t2].[MaxOfHoop Stress N/mm^2]) 
ORDER BY 
    t1.[load_case] DESC; 

SQL有ABS功能:

SELECT DISTINCT 
    t1.load_case, t2.[Data Location] AS Nodenr, 
    t2.[AbsOfHoop Stress N/mm^2] AS Expr1 
FROM 
    [tblFull1 04WoodsideTransportV335] AS t1, 
    (SELECT 
     [tblFull1 04WoodsideTransportV335].[Data Location], 
     ABS([tblFull1 04WoodsideTransportV335].[Hoop Stress N/mm^2]) AS[AbsOfHoop Stress N/mm^2] 
    FROM [tblFull1 04WoodsideTransportV335] 
    GROUP BY [tblFull1 04WoodsideTransportV335].[Data Location] 
    HAVING ((([tblFull1 04WoodsideTransportV335].[Data Location]) 
       In (SELECT [Data Location] 
        FROM [tblFull1 04WoodsideTransportV335] 
        GROUP BY [Data Location] 
        HAVING Count(*) > 1)) 
     AND ((ABS([tblFull1 04WoodsideTransportV335].[Hoop Stress N/mm^2])) Is Not Null)) 
    ORDER BY 
     [tblFull1 04WoodsideTransportV335].[Data Location]) AS t2 
WHERE 
    (((t1.[Hoop Stress N/mm^2])=[t2].[AbsOfHoop Stress N/mm^2])) 
ORDER BY 
    t1.load_case DESC; 
+0

ABS是不是分組功能,ABS(1,2- ,3,4,5)沒有意義,而最大(1,2,3,4,5)= 5 –

+0

當你的組(根據'數據位置')有多個值的箍應力,其中'abs( )'你想回來嗎? – shawnt00

回答

1

在SQL中, 「具有」 statment,你只能使用 「GROUP BY」 定義的列。對於其他列,必須在集合函數中使用,它們是: - AVG() - 返回平均值 - COUNT() - 返回行數 - FIRST() - 返回第一個值 - LAST ) - 返回的最後一個值 - MAX() - 返回最大的價值 - MIN() - 返回最小值 - SUM() - 返回總和

+0

啊哈,現在我明白了(謝謝!)。我希望我能像Max和Min一樣使用Abs函數。你知道這個問題的簡單解決方法嗎?=) – larssbr

相關問題