firefoxeye 2010-11-17 17:15
浏览 191
已采纳

不会sql语句....谁帮我优化下

[code="java"]select * from dbo.tbGoodsInfo where
(
id in (select goodsId from dbo.tbGoodsAddLink )
or id in(
select goodsId from dbo.tbGoodsBindBar where barUserId=
(select id from dbo.t_ClientInfo where bh='cdcs')
))
and auditStatus=0 and bupd!=-1
union
select * from dbo.tbGoodsInfo where (id not in (select goodsId from dbo.tbGoodsAddLink )
and id not in(select goodsId from dbo.tbGoodsBindBar where

barUserId=(select id from dbo.t_ClientInfo where bh='cdcs')
)) and auditStatus=0 and bupd!=-1[/code]
[size=medium]谢谢[/size]

  • 写回答

4条回答 默认 最新

  • p0程序员 2010-11-18 13:20
    关注

    上面语句有点问题

    [code="sql"]

    -- ftype 优先绑了地区、其次绑了网吧、最后其他
    select goods.*,
    (case when addr.id is not null then 1 else
    case when client.id is not null then 2 else
    3 end end
    ) as ftype
    from dbo.tbGoodsInfo as goods
    left join dbo.tbGoodsAddLink as addr on goods.id=addr.goodsId
    left join dbo.tbGoodsBindBar as bar on goods.id=bar.goodsId
    left join dbo.t_ClientInfo as client on bar.barUserId=client.id and client.bh='cdcs'
    where goods.auditStatus=0
    and goods.bupd!=-1
    order by ftype

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?