See Philip Franklin’s 1925 Trans. AMS paper Analytic transformations of everywhere dense point sets. Theorem I on p. 94 of Franklin's paper states:
For any two enumerable linear point sets, each everywhere dense on an open interval, an analytic function can be found which maps the two intervals on one another, and effects a one to one correspondence between the point sets.
I think Franklin's Theorems II and III can be used to answer your question, but I don't have time now to think about it.
For related results (some of which I believe may also address your question) and additional references, see my 15 March 2002 sci.math post in the thread a question on real-analytic functions at google sci.math archive or Math Forum sci.math archive.
(what follows was added 4 days later)
This morning I was in the middle of preparing a chronological list of references when I came across the following paper by accident, which has in its first couple of pages an excellent historical summary of results related to your questions.
[William] Stephen Watson and Petr Simon, Open subspaces of countable dense homogeneous spaces, Fundamenta Mathematicae 141 #2 (1992), 101-108. MR 93m:54038; Zbl 770.54017
Below are some relevant references I know of that are not in Watson/Simon’s bibliography: Cooper (1939), Melzak (1960), Ceder (1987), Omiecinski (1980, 1982, 1983, 1991), and Green (1939). Also, as I had already “looked up” the details for Morayne (1987) and Melzak (1959) (both of which are in Watson/Simon's bibliography), I’m leaving those below as well. Finally, I spent some time this morning typing quotes from Green (1939), a paper that does not seem to be freely available on the internet, so I’m leaving in those quotes as well.
Incidentally, regarding Franklin (1925): In the bibliographic listing for Franklin’s 1925 paper in Abraham A. Frankel’s book Abstract Set Theory (Franklin’s paper is cited in a footnote where order-uniqueness of countable unbounded dense linear orderings is proved), Frankel says to see H. Minkowski: Kongr. Heidelberg 1904, 171-172, 1905. This is freely available on the internet, but I do not know what Minkowski says or proves.
R. Cooper, Transformations of enumerable sets which are dense in an interval, Quarterly Journal of Mathematics (Oxford) 10 (1939), 247-251. MR 1,107c; Zbl 22.21302; JFM 65.0189.01
Zdzislaw Alexander Melzak, Existence of certain analytic homeomorphisms, Canadian Mathematical Bulletin 2 #2 (May 1959), 71-75. MR 21 #4215; Zbl 89.27603
Zdzislaw Alexander Melzak, A countable interpolation problem, Proceedings of the American Mathematical Society 11 #2 (April 1960), 304-306. MR 22 #2599; Zbl 91.04702
Michal Morayne, Measure preserving analytic diffeomorphisms of countable dense sets in $C^n$ and $R^n,$ Colloquium Mathematicum 52 #1 (1987), 93-98. MR 88f:28015; Zbl 627.28012
Jack Ceder: MR 88g:54040; Zbl 641.54020
Jan Omiecinski: MR 82i:26005 Zbl 485.26007; MR 84k:26021 Zbl 523.26019; MR 85j:26012 Zbl 549.26003; MR 92m:26007
John Willie Green, Functions which assume rational values at rational points, Duke Mathematical Journal 5 #1 (1939), 164-171. Zbl 20.35202; JFM 65.0327.03
For what it’s worth, Green was Andrew M. Bruckner’s Ph.D. advisor. What follows is the introduction to Green’s paper.
Of the continuous functions which assume rational values for rational values of the argument, the familiar examples either are extremely regular, as the rational or piecewise rational functions, or else exhibit some extremely irregular properties. For example, the functions $x(t),$ $y(t)$ defining Peano’s area filling curve assume rational values for rational $t$ and are nowhere derivable. Likewise the familiar function defined with respect to Cantor’s ternary set as $\frac{1}{2}$ on the middle extracted one-third, $\frac{1}{4}$ and $\frac{3}{4}$ on the extracted middle one-thirds of the left- and right-hand remaining intervals, respectively, etc. can be shown to assume rational values for rational $x.$ This function possesses a derivative at no point except points where it is piecewise rational. It is desired, then, to investigate what kinds of functions may possess the property of assuming rational values at rational points, which property we shall denote by (A). For example, it might be asked whether the only analytic functions with property (A) are the rational functions, or it might be asked if it is possible that a function exist with property (A), the function being analytic in no interval and yet, say, having a continuous derivative. The author has been informed that something of this nature was discussed in a conversation between Weierstrass and Hilbert and that Hilbert exhibited an example; however, no record of the conversation seems to be extant. Neither has the author been able to find the example mentioned in the literature, or to discover its exact nature. Consequently, some of the results obtainable may be of sufficient interest to warrant their exposition.
In the following, a rational complex number is a complex number such that both its real and imaginary parts are rational numbers.
THEOREM 1. There exist entire functions which possess the property (A) with respect to all rational complex numbers, and which are not rational functions.
In the following, rational point is a rational complex number and the functions are from $\mathbb C$ to $\mathbb C.$
THEOREM 2. Let $E_1$ and $E_2$ be any mutually disjoint sets of rational points. Then there exist analytic functions assuming rational values at points of $E_1$ and assuming rational values at no point of $E_2.$
Let $P(z) = a_{0} + a_{1}z + a_{2}z^{2} + \cdots$ converge for all $z \in {\mathbb C}$ and assume that $P(z)$ possesses property (A). Question 1 Is it possible for each $a_{k}$ to be a rational complex number and $P(z)$ to not be a rational function? Question 2 Is it possible for some of the $a_{k}$’s to be irrational?
THEOREM 3. The questions (1) and (2) above may be answered affirmatively.
In the following, all functions are from $\mathbb R$ to $\mathbb R.$
We define a function $f_{n}(x)$ as follows. Let $S_n$ be the set of points between zero and one of the form $m/(2^{n-1}n!)$ $(m=0,\;1,\;\cdots,\;2^{n-1}n!).$ Let $p<q$ be two consecutive points of $S_{n};$ then $f_{n}(x)$ is defined for $p \leq x \leq q$ as the continuous function vanishing at $p$ and $q,$ and with derivative $+1$ for $p < x< \frac{1}{2}(p+q)$ and derivative $-1$ for $\frac{1}{2}(p+q) < x < q.$ Then $0 \leq f_{n}(x) \leq \left(2^{n}n\right)^{-1},$ and $\Sigma_{1}^{\infty}f_{n}(x)$ converges uniformly. We define $f(x) = \Sigma_{n=1}^{\infty}f_{n}(x).$ It follows from well-known principles that $f(x)$ possesses a derivative at no point.
(For this last claim, Green cites p. 621 of Hobson, The Theory of Functions of a Real Variable, 1907.)
THEOREM 4. A function possessing property (A), with continuous $k$-th derivative and with $(k+1)$-th derivative nowhere, can be obtain by integrating $f(x)$ $k$ times and subtracting a polynomial of degree $k,$ possibly with irrational coefficients.