码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver基础

时间:2018-06-23 20:48:38      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:span   server   exchange   sts   if else   lin   SQ   oms   修改   

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 = 豪汇支付宝-测试商户
case when
技术分享图片
  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
if else
技术分享图片
 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;
exists
技术分享图片
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外层要用()
or
if exists (select f_id from t_banks ) select 1
else select 0;

 

sqlserver基础

标签:span   server   exchange   sts   if else   lin   SQ   oms   修改   

原文地址:https://www.cnblogs.com/SmileSunday/p/9218286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!