diff --git "a/\351\231\210\351\221\253\351\225\2222\346\234\21022\344\275\234\344\270\232/homework.js" "b/\351\231\210\351\221\253\351\225\2222\346\234\21022\344\275\234\344\270\232/homework.js" new file mode 100644 index 0000000000000000000000000000000000000000..2292651f7289a1a3649299cadd7c2ab595d9804e --- /dev/null +++ "b/\351\231\210\351\221\253\351\225\2222\346\234\21022\344\275\234\344\270\232/homework.js" @@ -0,0 +1,42 @@ +let mysql=require('mysql'); +let h=mysql.createConnection({host:"127.0.0.1",user:"root",password:"root",port:"3306",database:"yonghu"}); +h.connect(); + +let t=new Date(); +let time=t.getFullYear()+"/"+(t.getMonth()+1)+"/"+t.getDate()+" "+t.getHours()+":"+t.getMinutes()+":"+t.getSeconds(); +//console.log(time) + +//增 +let add="insert into unser values (null,'五五',215,'男','"+time+"','"+time+"')"; +h.query(add,(err,data)=>{ + console.log(err); + console.log(data); +}) + + +// //删 +let dele="delete from unser where yh_id=1"; +h.query(dele,(err,data)=>{ + console.log(err); + console.log(data); +}) + +//改 +let update="update unser set yh_name='小陈',update_time='"+time+"' where yh_id=2" +h.query(update,(err,data)=>{ + console.log(err); + console.log(data); +}) + + +//查 +let cha=function(page){ + let selec="select * from unser limit "+(6*page-6)+","+(6*page); + h.query(selec,(err,data)=>{ + console.log(err); + console.log(data); + }) +} + +cha(1); +h.end(); \ No newline at end of file diff --git "a/\351\231\210\351\221\253\351\225\2222\346\234\21022\344\275\234\344\270\232/homework2.js" "b/\351\231\210\351\221\253\351\225\2222\346\234\21022\344\275\234\344\270\232/homework2.js" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\351\231\210\351\221\253\351\225\2222\346\234\21023\344\275\234\344\270\232/homework.js" "b/\351\231\210\351\221\253\351\225\2222\346\234\21023\344\275\234\344\270\232/homework.js" new file mode 100644 index 0000000000000000000000000000000000000000..b483f5e57c5dc057f7ad841c93df7a8c1c0aa800 --- /dev/null +++ "b/\351\231\210\351\221\253\351\225\2222\346\234\21023\344\275\234\344\270\232/homework.js" @@ -0,0 +1,24 @@ +// ### 实现分页,能实现男女个数和总数的统计,能统计出(小于18) 和 18-45 和 45岁以上的人数(可以的话一条sql,分组,如果不能行就写多个sql统计) +let mysql=require('mysql'); +let h=mysql.createConnection({host:'127.0.0.1',user:'root',password:'root',port:'3306',database:'cxy'}); +h.connect(); + +//男女个数和总数的统计,统计出(小于18) 和 18-45 和 45岁以上的人数 +let sum1=`select type as '类型',count(type) '个数' from ( + select if(age<18,'小于18人数',if(age>18 and age<45,'18-45岁人数','大于45岁人数') + ) as type from user) as b group by type + union + select group_concat(sex,geshu) as '男女个数',sum(geshu) as '男女总数' from ( + select sex,count(sex) as geshu,'num' as num from user group by sex + ) as a group by num `; + +h.query(sum1,(err,data)=>{ + console.log(err); + console.log(data); +}) + + + + + +h.end(); \ No newline at end of file diff --git "a/\351\231\210\351\221\253\351\225\2222\346\234\21025\344\275\234\344\270\232/homework.js" "b/\351\231\210\351\221\253\351\225\2222\346\234\21025\344\275\234\344\270\232/homework.js" new file mode 100644 index 0000000000000000000000000000000000000000..a2f35fc0a905139fcdbe349c9dc14eb5449feb75 --- /dev/null +++ "b/\351\231\210\351\221\253\351\225\2222\346\234\21025\344\275\234\344\270\232/homework.js" @@ -0,0 +1,22 @@ +// 作业:第一个能不能使用promise的异步函数,封装下数据库的查询,二 把sequelize 配置完成,至少能查询一个表去看看sequelize的文档 +let fs=require('fs'); +let mysql=require('mysql'); +let h=mysql.createConnection({host:'127.0.0.1',user:'root',password:'root',port:'3306',database:"hjh"}) +function j(sql){ + // 有一个promise + return new Promise ((resolve,reject)=>{ + h.query(sql,(err,data)=>{ + if(err!=null){ + reject(err); + }else{ + resolve(data); + } + }) + }) +} +async function hh(sql){ + let content = await j(sql); + console.log(content); +} +hh("select * from user") +h.end(); \ No newline at end of file