Я очень новичок в SQL.У меня есть следующий запрос, и я хотел бы опустить записи NO_EOM
в моей таблице Excel.Может кто-нибудь предложить мне несколько советов о том, как это сделать?
Когда я пытаюсь отфильтровать его с помощью предложения WHERE
, я получаю сообщение об ошибке EOM_OR_BOM
столбец не существует.
SELECT
CASE WHEN [INVOICE_CREATE_DATE] BETWEEN 20180725 AND 20180731 THEN 'E0M_DATE'
WHEN [INVOICE_CREATE_DATE] BETWEEN 20180701 AND 20180707 THEN 'BOM DATE'
WHEN [INVOICE_CREATE_DATE] BETWEEN 20180825 AND 20180831 THEN 'E0M_DATE'
WHEN [INVOICE_CREATE_DATE] BETWEEN 20180801 AND 20180807 THEN 'BOM DATE'
WHEN [INVOICE_CREATE_DATE] BETWEEN 20180925 AND 20180931 THEN 'E0M_DATE'
WHEN [INVOICE_CREATE_DATE] BETWEEN 20180901 AND 20180907 THEN 'BOM DATE'
ELSE 'NO_EOM' END AS 'E0M_OR_BOM',
COUNT(1) AS Count,
[Sold_To_Text] AS [Sold to Customer Name],
[SO_Number] AS [Sales Order Number],
[SO_Create_By] AS [SO Creator],
[Delivery_Number] AS [Delivery Number],
[Invoice_Number] AS [Invoice Number],
[Invoice_Create_Date] AS [Invoice Creation Date]
FROM xxxx.yyy.BILLING_MONTHLY
WHERE [INVOICE_CREATE_DATE] >= 20180701
AND [SO_NUMBER] NOT LIKE '6%'
AND [SO_NUMBER] NOT LIKE '7%'
GROUP BY [INVOICE_CREATE_DATE],
[Sold_To_Text],
[SO_Number],
[SO_Create_By],
[Delivery_Number],
[Invoice_Number],
[Invoice_Create_Date]
ORDER BY EOM_OR_BOM DESC