查询在这里: 选择
FACDTE.QTR
,FACDTE.WK
,FACDTE."DATE"
,FACDTE.DIV
,FACDTE.DST
,FACDTE.FAC
,FACDTE.DAYS
,COALESCE(OOS.SCN,0) SCN
,RANK() OVER(
PARTITION BY FACDTE.QTR,FACDTE.WK,FACDTE."DATE"
ORDER BY COALESCE (CAST(OOS."OOS COUNT" AS INTEGER),'ns')) AS DIVRANK
,CAST(OOS."OOS COUNT" AS INTEGER) "OOS COUNT"
FROM
(
SELECT
FAC.PARENT_OP_AREA_CD DIV
,FAC.DISTRICT_FINANCE_CD DST
,FAC.STORE_ID FAC
,DTE.QUARTER_ID QTR
,DTE.WEEK_ID WK
,DTE.D_DATE "DATE"
,COUNT(DISTINCT(DTE.D_DATE)) DAYS
FROM LU_STORE_FINANCE FAC
JOIN (
SELECT
DTE_L1.D_DATE
,DTE_L1.WEEK_ID
,DTE_L1.QUARTER_ID
FROM LU_DAY_MERGE DTE_L1
JOIN (SELECT D_DATE FROM LU_DAY_MERGE
WHERE WEEK_ID=(SELECT DISTINCT(WEEK_ID) FROM LU_DAY_MERGE WHERE D_DATE =CURRENT_DATE -2)) DTE_L0 ON DTE_L0.D_DATE =DTE_L1.D_DATE AND DTE_L1.D_DATE < CURRENT_DATE
) DTE
ON DTE.D_DATE BETWEEN FAC.OPENED_DT AND FAC.CLOSED_DT AND
下面是我要提示的代码,以代替YYYYMMDD YYYYMMDD使用current_DATE的日期...我可以只输入?YYYYMMDD和YYYYMMDD吗?
FAC.PARENT_OP_AREA_CD ='17'并且不是FAC.STORE_ID IN(4904,3332,1478,0412,2631,1223)GROUP BY 1,2,3,4,5,6)FACDTE
LEFT JOIN
(SELECT
OOS_L1.STORE_ID FAC
,DTE_L2.WEEK_ID WK
,DTE_L2.D_DATE "DATE"
,AVERAGE(TOT_CT.TOT_OOS) AS "OOS COUNT"
,COUNT(DISTINCT(OOS_L1.SCAN_DT)) SCN
,SUM(CASE WHEN OOS_L1.PRODUCT_SOURCE_CD = 'W' THEN CASE WHEN ITM.DEPARTMENT_ID = 314 THEN OOS_L1.OOS_STR_SCAN_CNT ELSE 0 END ELSE 0 END) AS "DAIRY"
FROM
OOS_STORE_ITEM_DAY OOS_L1
JOIN (SELECT STORE_ID,SCAN_DT ,COUNT(UPC_ID) AS TOT_OOS FROM OOS_ITEM_DETAIL WHERE SCAN_TYP_CD = 'O' GROUP BY 1,2)TOT_CT
ON TOT_CT.STORE_ID = OOS_L1.STORE_ID AND TOT_CT.SCAN_DT=OOS_L1.SCAN_DT AND TOT_CT.TOT_OOS>49
JOIN LU_DAY_MERGE DTE_L2 ON OOS_L1.SCAN_DT=DTE_L2.D_DATE
JOIN LU_UPC ITM ON OOS_L1.UPC_ID = ITM.UPC_ID AND ITM.CORPORATION_ID = 1
GROUP BY 1,2,3) OOS
ON OOS.WK = FACDTE.WK AND OOS.FAC=FACDTE.FAC AND OOS."DATE" = FACDTE."DATE"
按1,2,3,4,5,6订购
答案 0 :(得分:0)
不知道,问题是什么。但是,如果您正在谈论Teradata SQL Assistant中的用于放置参数的功能(使用?-语法):
您可以使用关键字?在SQL Assistant中定义参数。只是地方?参数名称(无空格)在编辑器中的任何位置。 SQL Assistant将询问每个参数,并在查询发送到数据库之前对其进行搜索和替换。这些参数可以在编辑器中多次出现,您只需输入一次该值,每次出现时它将被替换。
SELECT *
FROM myWebOrders
where orderDate >= CURRENT_DATE - ?OrderHistory_Days
UNION ALL
SELECT *
FROM myRetailOrders
where orderDate >= CURRENT_DATE - ?OrderHistory_Days
或
SELECT TOP 50 *
FROM ?myTable