sql语句

with 

begin_run_count as(

SELECT TOP 1 *

FROM [dbo].[machine_stats_minutely1]

WHERE record_time >= '${dDate+' '+beginTime}' 

  AND record_time < '${dDate+' '+endTime}'

ORDER BY record_time ASC

),

 想修改成 如果beginTime和endTime都有值where 为

record_time >= '${dDate+' '+beginTime}' 

  AND record_time < '${dDate+' '+endTime}'

 否则where 语句为

record_time >= '${dDate}' 

  AND record_time < '${dDate}'

SQL yzm209396 发布于 4 天前
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
用户k6280494Lv6专家互助
发布于4 天前(编辑于 4 天前

${if(len(beginTime)=0&&len(endTime)=0,"record_time >= '"+dDate+"' AND record_time < '"+dDate+"'","record_time >= '"+dDate+' '+beginTime+"'  AND record_time < '"+dDate+' '+endTime+"'")}

================

with 

begin_run_count as(

SELECT TOP 1 *

FROM [dbo].[machine_stats_minutely1]

WHERE 1=1

${if(len(beginTime)=0&&len(endTime)=0,"and record_time >= '"+dDate+"' AND record_time < '"+dDate+"'","and record_time >= '"+dDate+' '+beginTime+"'  AND record_time < '"+dDate+' '+endTime+"'")}

)

最佳回答
0
snrtuemcLv8专家互助
发布于4 天前

with 

begin_run_count as(

SELECT TOP 1 *

FROM [dbo].[machine_stats_minutely1]

WHERE 1=1

${if(len(beginTime)>0&&len(endTime)>0),"and record_time >= '"+dDate+' '+beginTime+"'  AND record_time < '"+dDate+' '+endTime+"'"," and record_time >= '"+dDate+"'  AND record_time < '"+dDate+"'"

)}

ORDER BY record_time ASC

)

最佳回答
0
技术支持--哈哈Lv4初级互助
发布于4 天前(编辑于 4 天前

image.png

  • 4关注人数
  • 48浏览人数
  • 最后回答于:4 天前
    请选择关闭问题的原因
    确定 取消
    返回顶部