andrija djurovic
2011-Aug-10 06:37 UTC
[R] subqueries in sqlQuery function (package RODBC)
Hi R users. sorry for missing example and if question is to general but I am wondering if it is possible to execute subqueries in function sqlQuery (package RODBC) with opened connection with Excel or SQL server 2000. I couldn't find any example of this. And if it is possible what should be a correct syntax for this query: SELECT ct,COUNT(*) as n FROM (SELECT COUNT(*) AS ct FROM children GROUP BY family_id) AS x GROUP BY ct; sqlQuery(connecton, " CORRECT SYNTAX ") (This query is an example from book Data Manipulation with R, Phil Spector, page 47) Thanks for any help Andrija [[alternative HTML version deleted]]
Prof Brian Ripley
2011-Aug-10 08:16 UTC
[R] subqueries in sqlQuery function (package RODBC)
In what sense is this a 'subquery'? It is just an SQL command (write it on one line, no terminating ;, which is not part of the query). On Wed, 10 Aug 2011, andrija djurovic wrote:> Hi R users. > > sorry for missing example and if question is to general but I am wondering > if it is possible to execute subqueries in function sqlQuery (package RODBC) > with opened connection with Excel or SQL server 2000. I couldn't find any > example of this. > > And if it is possible what should be a correct syntax for this query: > > SELECT ct,COUNT(*) as n > FROM (SELECT COUNT(*) AS ct FROM children > GROUP BY family_id) AS x > GROUP BY ct; > > sqlQuery(connecton, " CORRECT SYNTAX ") > > (This query is an example from book Data Manipulation with R, Phil Spector, > page 47) > > Thanks for any help > > Andrija > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595