173 lines
4.5 KiB
Plaintext
173 lines
4.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"db = pymysql.connect(\"localhost\",\"songyi\",\"yylzs\",\"mydata\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"cursor.execute(\"SELECT VERSION()\")\n",
|
|
"data = cursor.fetchone()\n",
|
|
"print (\"Database version : %s \" % data)\n",
|
|
"db.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"db = pymysql.connect(\"localhost\",\"songyi\",\"yylzs\",\"mydata\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = \"select id,name from sports_person where name= %s\"\n",
|
|
"cursor.execute(sql, ('张联红',))\n",
|
|
"result = cursor.fetchone()\n",
|
|
"print(result)\n",
|
|
"db.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"db = pymysql.connect(\"localhost\",\"songyi\",\"yylzs\",\"mydata\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = \"select id,name from sports_person\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"result = cursor.fetchone()\n",
|
|
"print(\"人员信息:\")\n",
|
|
"print(result)\n",
|
|
"sql = \"select id,name from sports_item\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"result = cursor.fetchone()\n",
|
|
"print(\"\\n运动项目信息:\")\n",
|
|
"print(result)\n",
|
|
"db.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"db = pymysql.connect(\"localhost\",\"songyi\",\"yylzs\",\"mydata\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = \"select a.target_id,b.name from sports_item_target as a,sports_target as b where a.target_id=b.id\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"re_ta = {}\n",
|
|
"print(\"\\n运动项目信息:\")\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results:\n",
|
|
"# print (\"%d--%s\" %(result[0],result[1]))\n",
|
|
" re_ta[result[0]] = result[1]\n",
|
|
" print(\"re_ta[%d]= #%s\" %(result[0],result[1]))\n",
|
|
"print(re_ta)\n",
|
|
"db.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"db = pymysql.connect(\"localhost\",\"songyi\",\"yylzs\",\"mydata\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"person_id = \n",
|
|
"record_date = ''\n",
|
|
"item_id =\n",
|
|
"re_ta = {}\n",
|
|
"re_ta[1]= #运动距离\n",
|
|
"re_ta[2]= #运动时间\n",
|
|
"re_ta[3]= #平均配速\n",
|
|
"re_ta[4]= #平均速度\n",
|
|
"re_ta[5]= #平均步频\n",
|
|
"re_ta[6]= #平均步幅\n",
|
|
"re_ta[7]= #步数\n",
|
|
"re_ta[8]= #平均心率\n",
|
|
"re_ta[9]= #最大心率\n",
|
|
"re_ta[10]= #无氧耐力\n",
|
|
"re_ta[11]= #有氧耐力\n",
|
|
"re_ta[12]= #最大步频\n",
|
|
"re_ta[13]= #最快配速\n",
|
|
"sql = \"select * from sports_person\"\n",
|
|
"db.close()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-03-27T06:10:30.861854Z",
|
|
"iopub.status.busy": "2023-03-27T06:10:30.861008Z",
|
|
"iopub.status.idle": "2023-03-27T06:10:30.877436Z",
|
|
"shell.execute_reply": "2023-03-27T06:10:30.876689Z",
|
|
"shell.execute_reply.started": "2023-03-27T06:10:30.861813Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"100\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"test\"]\n",
|
|
"renyuan = set()\n",
|
|
"for x in mycol.find():\n",
|
|
" renyuan.add(x['name'])\n",
|
|
"print(len(renyuan))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|