佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

12
返回列表 发新帖
楼主: ocm1

select 的问题

  [复制链接]
 楼主| 发表于 21-10-2010 01:03 PM | 显示全部楼层
应该解决了,我试用group by.

你们很好人,谢谢
回复

使用道具 举报


ADVERTISEMENT

发表于 21-10-2010 01:54 PM | 显示全部楼层
where xyear >=2010 and xmonth>=5
ocm1 发表于 20-10-2010 02:39 PM



    這句根本有問題,還很嚴重!!

你的語句要大過2010 和 大過 5 月。

如果 2011 年 4月你就選不出了。
回复

使用道具 举报

发表于 7-12-2010 12:00 PM | 显示全部楼层
本帖最后由 lebellebebe 于 7-12-2010 12:17 PM 编辑
  1. create table sales
  2.         (xinvoiceno int
  3.         ,xuser_id varchar(20)
  4.         ,xyear int
  5.         ,xmonth int
  6.         ,xRM int
  7.         ,constraint pk_sales primary key clustered(xinvoiceno)
  8. )
复制代码

  1. insert sales
  2.         (xinvoiceno,xuser_id,xyear,xmonth,xRM)
  3. values
  4.         (1001, 'A21012', 2009, 5, 100)
  5.         ,(1002, 'A10099', 2009, 6, 120)
  6.         ,(1003, 'A34300', 2010, 5, 300)
  7.         ,(1004, 'A30002', 2010, 10, 400)
  8.         ,(1005, 'A33302', 2007, 10, 400) -- final result return this &
  9.         ,(1006, 'B8865J', 2008, 12, 400) -- this
  10.         ,(1007, 'B8865J', 2010, 7, 1000)
  11.         ,(1008, 'A34300', 2006, 9, 1500)
复制代码


SQL query (check syntax, not entirely correct)


  1. select *
  2. from sales s
  3. where (s.xmonth <= datepart(mm, (dateadd(month, -24, getdate()))) and
  4.       s.xyear <= datepart(yyyy, (dateadd(year, -2, getdate()))))  and
  5. not exists
  6.     (select *
  7.      from sales s2
  8.      where s2.xuser_id = s.xuser_id and
  9.            (s2.xmonth <= datepart(mm, (dateadd(month, -6, getdate())))) and
  10.            (s2.xyear = datepart(yyyy, getdate())))
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 17-11-2025 06:21 PM , Processed in 0.114866 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表