首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

复杂的查询解决办法

2012-04-01 
复杂的查询select * from ((select name,count(*) from table where date between 20100101 and 20100131

复杂的查询
select * from ((select name,count(*) from table where date between 20100101 and 20100131 group by name) a full join (select name,count(*) from table where date between 20100201 and 20100128 group by name) b on a.name=b.name full join (select name,count(*) from table where date between 20100301 and 20100331 group by name) c on b.name=c.name ) d

我想把3个月每个月的统计出来,再放在一起做对比,是不是我哪里写错了?


[解决办法]
结果有什么不对的地方描述一下。
[解决办法]
VFP9支持,你的VFP版本?贴记录及要求结果出来看看
[解决办法]

SQL code
*环境初始化Close TablesLocal alluse "E:\模拟表.dbf" Alias t_Demo In 0*创建姓名唯一索引Select distinct t_Demo.Name from t_Demo into cursor c_Name_Idx*创建临时表:存放最终比对的表格式Create Cursor c_Month_Count(User_Name C(30), Jan_Count N(10, 0), Feb_Count N(10, 0), Mar_Count N(10, 0))*实现数据匹配Select c_Name_IdxScan    lsUser_Name = Alltrim(c_Name_Idx.Name)        Calculate cnt() For Substr(Dtos(t_Demo.Date), 5, 2)  = "01" .And. Alltrim(t_Demo.Name) = lsUser_Name to lnJan_Count in t_Demo    &&一月的记录数    Calculate cnt() For Substr(Dtos(t_Demo.Date), 5, 2)  = "02" .And. Alltrim(t_Demo.Name) = lsUser_Name to lnFeb_Count in t_Demo    &&二月的记录数    Calculate cnt() For Substr(Dtos(t_Demo.Date), 5, 2)  = "03" .And. Alltrim(t_Demo.Name) = lsUser_Name to lnMar_Count in t_Demo    &&三月的记录数        *如需统计 4~ 12月份 XX 用户的记录,自行向后添加条件(向临时表 c_Month_Count 中也添相应的存放字段)        Insert into c_Month_Count(User_Name, Jan_Count, Feb_Count, Mar_Count) values(lsUser_Name, lnJan_Count, lnFeb_Count, lnMar_Count)        lsUser_Name = ""    Store 0 to lnJan_Count, lnFeb_Count, lnMar_Count    EndscanRelease lsUser_Name, nJan_Count, lnFeb_Count, lnMar_CountSelect c_Month_Countbrow
[解决办法]
贴记录及要求结果出来看看

[解决办法]
SQL code
--杯具,你这是VFP语法,还是SQL语法--VFP 9SELECT name,CNT(*) as xCnt,IIF(BETWEEN(date,"20100101","20100131"),"1",; IIF(BETWEEN(date,"20100201","20100228"),"2","3")) as cGrp ;FROM tmp GROUP BY name,std--SQLselect name,left(date,6) as ym,count(*) as cnt from tmp group by left(date,6)
[解决办法]
你帖出是结果吧,原来表什么样式。

热点排行