数据集sql问题咨询

WITH A AS (

SELECT Area,

COUNT(1) AS Status

FROM sss

GROUP BY Area

UNION

SELECT Area,

COUNT(1) AS Status

FROM sss1

GROUP BY Area

UNION

SELECT Area,COUNT(1) AS Status

FROM sss2

GROUP BY Area

)

SELECT A.AREA,'年' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE YEAR(A.Date)=YEAR(GETDATE())

GROUP BY A.AREA

UNION

SELECT A.AREA,'月' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE MONTH(A.DATE) =MONTH(GETDATE())

GROUP BY A.AREA

如何修改   需要给Time_dimension参数

FineReport FANGHJ 发布于 2023-11-21 17:14 (编辑于 2023-11-21 17:20)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
CovidLv3高级互助
发布于2023-11-21 17:15(编辑于 2023-11-21 17:22)

有where 没 from?

看不懂

---------

WITH A AS (

SELECT Area,

COUNT(1) AS Status

FROM sss

GROUP BY Area

UNION

SELECT Area,

COUNT(1) AS Status

FROM sss1

GROUP BY Area

UNION

SELECT Area,COUNT(1) AS Status

FROM sss2

GROUP BY Area

)

select * from (

SELECT A.AREA,'年' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE YEAR(A.Date)=YEAR(GETDATE())

GROUP BY A.AREA

UNION

SELECT A.AREA,'月' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE MONTH(A.DATE) =MONTH(GETDATE())

GROUP BY A.AREA

) t where 1=1 ${if(len(控件名)==0,"",IF(控件名=="年"," and t.Time_dimension='年'"," and t.Time_dimension='月'")}

  • FANGHJ FANGHJ(提问者) 有的 就是主要问题是赋值的如何给参数
    2023-11-21 17:16 
  • Covid Covid 回复 FANGHJ(提问者) 逗号后面的有from?而且逗号后面的又不是子表(临时表)前面的逗号不需要
    2023-11-21 17:18 
  • FANGHJ FANGHJ(提问者) 回复 Covid 已完善语句 你看看
    2023-11-21 17:19 
  • Covid Covid 回复 FANGHJ(提问者) 你确定你 的示例SQL和实际的没区别?
    2023-11-21 17:29 
最佳回答
0
JL98Lv6中级互助
发布于2023-11-21 17:30

你的A.date没有这个字段啊,需要Time_dimension参数那就在包一层就好了

image.png

-------------------------------------------------------------------------------------------------------------

WITH A AS (

SELECT Area,

COUNT(1) AS Status

FROM sss

GROUP BY Area

UNION

SELECT Area,

COUNT(1) AS Status

FROM sss1

GROUP BY Area

UNION

SELECT Area,COUNT(1) AS Status

FROM sss2

GROUP BY Area

),

B AS (

SELECT A.AREA,'年' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE YEAR(A.Date)=YEAR(GETDATE())

GROUP BY A.AREA

UNION

SELECT A.AREA,'月' AS Time_dimension,SUM(A.Status) Status

FROM A

WHERE MONTH(A.DATE) =MONTH(GETDATE())

GROUP BY A.AREA

)

SELECT * FROM B WHERE  Time_dimension = '${Time_dimension}'

  • 2关注人数
  • 197浏览人数
  • 最后回答于:2023-11-21 17:30
    请选择关闭问题的原因
    确定 取消
    返回顶部