Commits

Matt Bone committed 563ee21

latest

Comments (0)

Files changed (1)

database_examples.ipynb

        "output_type": "pyout",
        "prompt_number": 3,
        "text": [
-        "<sqlite3.Cursor at 0x1506810>"
+        "<sqlite3.Cursor at 0x17e1810>"
        ]
       }
      ],
       "student_data = [\n",
       "                {'id': 1, 'name': 'matt', 'age': 29},\n",
       "                {'id': 2, 'name': 'alice', 'age': 33},\n",
-      "                {'id': 3, 'name': 'same', 'age': 25},\n",
+      "                {'id': 3, 'name': 'sam', 'age': 25},\n",
       "                ]"
      ],
      "language": "python",
        "output_type": "pyout",
        "prompt_number": 6,
        "text": [
-        "<sqlite3.Cursor at 0x1506810>"
+        "<sqlite3.Cursor at 0x17e1810>"
        ]
       }
      ],
       {
        "metadata": {},
        "output_type": "pyout",
-       "prompt_number": 8,
+       "prompt_number": 7,
        "text": [
-        "<sqlite3.Cursor at 0x1506810>"
+        "<sqlite3.Cursor at 0x17e1810>"
        ]
       }
      ],
-     "prompt_number": 8
+     "prompt_number": 7
     },
     {
      "cell_type": "code",
      "language": "python",
      "metadata": {},
      "outputs": [],
+     "prompt_number": 8
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Find all students under 30"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "[student for student in student_data if student['age'] < 30]"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 9,
+       "text": [
+        "[{'age': 29, 'id': 1, 'name': 'matt'}, {'age': 25, 'id': 3, 'name': 'same'}]"
+       ]
+      }
+     ],
      "prompt_number": 9
     },
     {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "```select * from students where age < 30;```"
+     ]
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "Find the grades of all students less who are less than 30."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "grades_less_than_30 = []\n",
+      "for student in student_data:\n",
+      "    if student['age'] < 30:\n",
+      "        for grade in grade_data:\n",
+      "            if grade['student_id'] == student['id']:\n",
+      "                grades_less_than_30.append(grade)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 10
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "grades_less_than_30"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 11,
+       "text": [
+        "[{'course': 'markup', 'grade': '85', 'id': 1, 'student_id': 1},\n",
+        " {'course': 'compilers', 'grade': '77', 'id': 2, 'student_id': 1},\n",
+        " {'course': 'markup', 'grade': '85', 'id': 5, 'student_id': 3},\n",
+        " {'course': 'operating systems', 'grade': '82', 'id': 6, 'student_id': 3}]"
+       ]
+      }
+     ],
+     "prompt_number": 11
+    },
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "```select students.name, grades.grade from grades inner join students on grades.student_id=students.id where students.age < 30;```"
+     ]
+    },
+    {
      "cell_type": "code",
      "collapsed": false,
      "input": [],