smelly_pretty
smelly_pretty
2011-11-17 14:10
浏览 411
已采纳

求解马士兵视频里关于数据库sql语句的笔试题

题目在附件中!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • u011606457
    _1_1_7_ 2011-11-17 15:01
    已采纳

    [code="sql"]
    select * from
    (select a.productname,rednum-bluenum as diffnum
    from (select productname,sum(num) as rednum from product where color='红色' group by productname) as a,
    (select productname,sum(num) as bluenum from product where color='蓝色' group by productname) as b
    where a.productname=b.productname) where diffnum>0

    select a.productname as 产品,rednum as 红色,bluenum as 蓝色
    from (select productname,sum(num) as rednum from product where color='红色' group by productname) as a,
    (select productname,sum(num) as bluenum from product where color='蓝色' group by productname) as b
    where a.productname=b.productname[/code]

    点赞 评论
  • jiangguangxian
    jiangguangxian 2011-11-17 15:30

    [code="java"]
    select * from
    (
    select a.productname,rednum-bluenum as diffnum

    from
    (
    select productname,sum(num) as rednum from product where color='红色' group by productname
    ) as a,

    (
    select productname,sum(num) as bluenum from product where color='蓝色' group by productname
    ) as b

    where a.productname=b.productname ) as t
    where t.diffnum>0
    [/code]

    对楼上做了稍稍的修整,楼上的是正确,分可以给楼上的了。

    点赞 评论
  • yanjinke
    yanjinke 2011-11-17 15:33

    楼上的正解,有没有考虑到性能问题呢?

    点赞 评论

相关推荐