楼主: jjj1989
843 0

[问答] 把SQL转到R,但是搞不清楚SQL 求解 [推广有奖]

  • 0关注
  • 1粉丝

本科生

79%

还不是VIP/贵宾

-

威望
0
论坛币
313 个
通用积分
1.3209
学术水平
2 点
热心指数
4 点
信用等级
0 点
经验
1049 点
帖子
78
精华
0
在线时间
120 小时
注册时间
2008-9-21
最后登录
2024-3-25

20论坛币
如题 对SQL的结构不是很了解,因为只是个参考的code 被要求转到R上面用RSQLite。。。。有对应的R代码能把这些相应的代码用R实现么?

CREATE INDEX IF NOT EXISTS idx1_firstcontact ON firstcontact (studentid);                           --create index
CREATE INDEX IF NOT EXISTS idx2_firstcontact ON firstcontact (studentid ,createddate,modifieddate); --create index


with
firstcontact_std
   as
   ( select   studentid         
             ,date(createddate)  createddate        
             ,date(modifieddate) modifieddate
                 from firstcontact
              group by studentid,date(createddate),date(modifieddate))
,firstcontact_res
   as
   ( select   studentid         
             ,date(createddate)  createddate        
             ,date(modifieddate) modifieddate
             ,responselabel
             ,surveylabelnumber
                 from firstcontact  
     )     
select
fc.studentid            "V1"
,fc.createddate          "V2"
,fc.modifieddate         "V3"
,(select responselabel from firstcontact_res Q13_1 where Q13_1.surveylabelnumber ='Q13_1' and fc.studentid=Q13_1.studentid and fc.createddate=Q13_1.createddate and fc.modifieddate=Q13_1.modifieddate limit 1 ) "Q13_1"
,(select responselabel from firstcontact_res Q65_TEXT where Q65_TEXT.surveylabelnumber ='Q65_TEXT' and fc.studentid=Q65_TEXT.studentid and fc.createddate=Q65_TEXT.createddate and fc.modifieddate=Q65_TEXT.modifieddate limit 1 ) "Q65_TEXT"
from firstcontact_std fc  
;

关键词:sql Modified response created Contact sql
您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-26 14:20