请教各位高手.
我用MICROSOFT ACCESS写SQL。语句如下:
SELECT SHEET1.CONSIGNEE, SUM(SHEET1.TEU) AS TEU, SHEET1.TRADE, SHEET1.[P/C]
FROM (SELECT *
FROM SHEET1
WHERE SHEET1.[P/C] = 'C' and SHEET1.TRADE='AEX'
ORDER BY SHEET1.CONSIGNEE DESC)
GROUP BY SHEET1.CONSIGNEE, SHEET1.TRADE, SHEET1.[P/C]
ORDER BY SUM(SHEET1.TEU) DESC;
第一次编译ok,但是,第二次就不行了,总是出现错误提示,如下:
Invalid bracketing of name'SELECT *
FROM SHEET1
WHERE SHEET1.[P/C'
我查了一下语句,发现,系统自动加了些东西,如下:
SELECT SHEET1.CONSIGNEE, SUM(SHEET1.TEU) AS TEU, SHEET1.TRADE, SHEET1.[P/C]
FROM [SELECT *
FROM SHEET1
WHERE SHEET1.[P/C] = 'C' and SHEET1.TRADE='AEX'
ORDER BY SHEET1.CONSIGNEE DESC]. AS [%$##@_Alias]GROUP BY SHEET1.CONSIGNEE, SHEET1.TRADE, SHEET1.[P/C]
ORDER BY SUM(SHEET1.TEU) DESC;
现在只能每次用的时候重新贴一遍原语句。太麻烦了。
请教高手,这个问题如何解决
SELECT a.CONSIGNEE, SUM(a.TEU) AS TEU, a.TRADE, a.[P/C]
FROM (SELECT *
FROM SHEET1
WHERE SHEET1.[P/C] = 'C' and SHEET1.TRADE='AEX'
ORDER BY SHEET1.CONSIGNEE DESC) as a
GROUP BY a.CONSIGNEE, a.TRADE, a.[P/C]
ORDER BY SUM(a.TEU) DESC;
仔细看了一下,似乎可以简化为如下:
SELECT CONSIGNEE, SUM(TEU) AS TEU, TRADE, [P/C]
FROM SHEET1
WHERE [P/C] = 'C' and TRADE='AEX'
GROUP BY CONSIGNEE, TRADE, [P/C]
ORDER BY SUM(TEU) DESC;
你好,感谢您的回复。
SELECT CONSIGNEE, SUM(TEU) AS TEU, TRADE, [P/C]
FROM SHEET1
WHERE [P/C] = 'C' and TRADE='AEX'
GROUP BY CONSIGNEE, TRADE, [P/C]
ORDER BY SUM(TEU) DESC;
这个虽然可以通过编译,但是结果不对。
这要看与你写的查询结果不一致?还是与你需要的结果不一致?
和用原语句查出的结果不一致。
SORRY,已经解决了。您写的语句没错,我贴的时候,有一个字段漏掉了。谢谢
呵呵,我想也不应该错的。

哈哈,是我粘贴的问题。谢谢了
总记录:9篇 页次:1/1 9 1 :