今天面试的两道sql题,回来发现都做错了

两道原题见这里
http://www.cnblogs.com/springwind/archive/2008/06/28/1231527.html
第一题很简单 只不过当时题意理解错了 不多说
第二题整理一下思路:先获取每个时间点即每天,然后按照广告位置和每天进行分组,得到每天每个广告位的数量,然后基本就出来了,附我的sql,未整理,其中t我写死的数据,用个临时表替换一下就可以了
引用内容 引用内容

with t as(
    select '2006-11-01' as 'date'
    union all
    select '2006-11-02'
    union all
    select '2006-11-03'
    union all
    select '2006-11-04'
    union all
    select '2006-11-05'
)
select * from (
    select count(*) total, positioncode, t.date
    from orders a
    left join t on t.date between startdate and enddate
    group by positioncode,t.date
) a
left join Product b on b.positioncode = a.positioncode
inner join orders c on c.positioncode = a.positioncode
where total > showcount
order by date, a.positioncode



[本日志由 Rwing 于 2009-03-24 03:43 PM 编辑]
文章来自: 本站原创
引用通告地址: http://www.rwing.cn/trackback.asp?tbID=111
Tags:
评论: 1 | 引用: 0 | 查看次数: 3446
  • 1
MJJ啊 [2009-03-25 05:37 PM]
286来关注下
  • 1
发表评论
昵 称:
密 码: 游客发言不需要密码.
机器码: 为了防止恶意评论,请输入  1234
验证码:
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 开启