select t.replaty_title ,
case when t.replaty_linkurl is null then '' else 'aaa'||to_char(t.replaty_linkurl) end as replaty_linkurl ---新增條件判斷
from wx_replyinfo_tb t
where t.menu_id =12 and t.replaty_state =1
sql 查詢本週本月問題
---求相差天數
select datediff(day,'2004-01-01',getdate())
--1.乙個月第一天的
select dateadd(mm, datediff(mm,0,getdate()), 0)
--2.本週的星期一
select dateadd(wk, datediff(wk,0,getdate()), 0)
select dateadd(wk,datediff(wk,0,getdate()),6)
--3.一年的第一天
select dateadd(yy, datediff(yy,0,getdate()), 0)
--4.季度的第一天
select dateadd(qq, datediff(qq,0,getdate()), 0)
--5.當天的半夜
select dateadd(dd, datediff(dd,0,getdate()), 0)
--6.上個月的最後一天
select dateadd(ms,-3,dateadd(mm, datediff(mm,0,getdate()), 0))
--7.去年的最後一天
select dateadd(ms,-3,dateadd(yy, datediff(yy,0,getdate()), 0))
--8.本月的最後一天
select dateadd(ms,-3,dateadd(mm, datediff(m,0,getdate())+1, 0))
--9.本年的最後一天
select dateadd(ms,-3,dateadd(yy, datediff(yy,0,getdate())+1, 0))
--10.本月的第乙個星期一
select dateadd(wk,
datediff(wk,0,dateadd(dd,6-datepart(day,getdate()),getdate())), 0)
--查詢本週註冊人數
select count(*) from [user]
where datediff(week,create_day-1,getdate())=0
--上週註冊人數
select count(*) from [user]
where datediff(week,create_day-1,getdate())=1
--本月註冊人數
select count(*) from [user]
where datediff(month,create_day,getdate())=0
--上月註冊人數
select count(*) from [user]
where datediff(month,create_day,getdate())=1
--如果要效率,這樣寫查詢
--查詢本週註冊人數
select count(*) from [user]
where create_day>=dateadd(day,2-datepart(weekday,getdate()),convert(varchar,getdate(),112))
and create_day=dateadd(day,-5-datepart(weekday,getdate()),convert(varchar,getdate(),112))
and create_day=dateadd(day,1-day(getdate()),convert(varchar,getdate(),112))
and create_day=dateadd(month,-1,dateadd(day,1-day(getdate()),convert(varchar,getdate(),112)))
and create_day--上月
select count(*) from user
where datepart(mm,create_day) = datepart(mm,getdate()) - 1
--本週
select count(*) from [user]
where datediff(dd,create_day,getdate()) <= datepart(dw,getdate())
--上週
select count(*) from [user]
where datediff(dd,create_day,(getdate() - datepart(dw,getdate()))) <= 7
--本月
select count(*) from [user]
where datepart(mm,create_day) = datepart(mm,getdate())
--上月
select count(*) from [user]
where datepart(mm,create_day) = datepart(mm,getdate()) - 1
學習
month(create_day)=month(getdate())本月
month(create_day)=month(getdate())-1 上月
補充 查詢今日所有的
select * from feedback where (datediff(d,fedtime,getdate())=0) order by fedid desc
sql查詢本週本月本年
1.乙個月第一天的 select dateadd mm,datediff mm,0,getdate 0 2.本周一 select dateadd wk,datediff wk,0,getdate 0 select dateadd wk,datediff wk,0,getdate 6 3.一年的第一天...
sql 查詢本週本月問題
sql 查詢本週本月問題 求相差天數 select datediff day,2004 01 01 getdate 1.乙個月第一天的 select dateadd mm,datediff mm,0,getdate 0 2.本週的星期一 select dateadd wk,datediff wk,0...
mySql 查詢當天 本週 本月等語句
當天 select from 表名 where date format e.createtime,y m d date format curdate y m d 昨日 select column name s from 表名 where date format 時間字段,y m d date for...