sqlserver基础
Posted 珍惜美好时光!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver基础相关的知识,希望对你有一定的参考价值。
1、示例
-- 注意用了group by 之后,这里要与聚合函数联合使用,例如 max(f_id) select k.* from( select min(d.f_type) as f_type, f_user, max(f_surplus) as f_surplus, min(f_checkTime) as f_checkTime, min(f_errorMoney) as f_errorMoney, max(d.f_paytype) as f_paytype, max(y.f_id) as f_id, max(y.f_isExchange) as f_isExchange, max(y.f_state) as f_state, count(case when isnull(d.f_state,0) = 1 then 1 end) as f_succNum , -- 新写法 count(case when isnull(d.f_state,0) <> 1 then 1 end) as f_faildNum, -- 新写法 count(case when isnull(d.f_state,-1) = -1 then 1 end) as f_faildrz, count(case when isnull(d.f_state,-1) = 0 then 1 end) as f_faildcl from [dbo].[t_DeltaOnline] d with(nolock) inner join t_YeePayAccounts y with(nolock) on y.f_id = d.f_fkzl where isnull(d.f_del,0)=0 and ISNULL(Y.f_del,0)<>1 and ISNULL(Y.f_del,0)<>2 -- ISNULL(Y.f_del,0)<>2 group by f_user ) k where k.f_user = ‘豪汇支付宝-测试商户‘
if exists (select * from t_Mypurse with(nolock) where f_payin = 1 and f_otherAccounts is not null and datediff(hh,f_time,getdate())< 48) select 1 else select 0
DateDiff(dd,f_time,getdate())=0 -- 当天 datediff(hh,f_time,getdate())< 48 --48小时内
-- charindex(‘‘, column) <=0 和 not like的意思一样,%匹配多个字符 select f_id, f_showname from t_Banks with(nolock) where charindex(‘約‘,f_showname)<=0 and f_MasterID=0 and (f_number<5000 or (f_number > 10000 and f_number <=11000)) and isnull(f_del,0)=0 and (f_showname like ‘%[A-D]%‘ or f_showname like ‘%F%‘ ) ORDER BY f_number ASC
-- 银行取款修改暂停分配, 0和1之间的切换 update t_admin set f_stop=1- isnull(f_stop,0) where f_accounts=‘‘ and isnull(f_del,0)=0 select * from t_ExchangeSet; -- 根据类型获取自动讯息 select f_id,f_msgType from t_autoMsgSet with(nolock) where f_type = 1 and f_target & 16 = 16
-- 具有分笔的母单id select f_id from t_exchange t where exists ( select f_money,f_fee,f_status,f_serial,f_bookCode from t26w.dbo.t_subCash where f_serial = t.f_id and f_type=1 and f_status in (2, 3, 4, 6) ) order by f_id asc;
SELECT Bank.f_ShowName as MemberBankName , BankLevel.f_majordomo ,BankLevel.f_StupeSurplus FROM t_Banks_Level as BankLevel with(nolock) left join t_Banks as Bank with(nolock) on BankLevel.f_BanksID=Bank.f_id WHERE Bank.f_ShowName is not NULL and isnull(bank.f_del,0)=0 and isnull(f_Sort,0) <=100 AND ( -- or外层要用() ( f_majordomo = ‘F‘ AND f_StupeSurplus = 7000) OR( f_majordomo = ‘F‘ AND f_StupeSurplus = 7000) OR ( f_majordomo = ‘Q‘ AND f_StupeSurplus = 1001) OR( f_majordomo = ‘测试‘ AND f_StupeSurplus = 5001) OR ( f_majordomo = ‘测试‘ AND f_StupeSurplus = 5001) OR( f_majordomo = ‘测试‘ AND f_StupeSurplus = 5001) ) -- or外层要用()
if exists (select f_id from t_banks ) select 1 else select 0;
以上是关于sqlserver基础的主要内容,如果未能解决你的问题,请参考以下文章
[vscode]--HTML代码片段(基础版,reactvuejquery)