diff --git "a/\345\255\243\351\233\250\346\264\201/\344\275\234\344\270\232/2-23.\347\273\237\350\256\241\344\270\252\346\225\260\344\275\234\344\270\232/work.js" "b/\345\255\243\351\233\250\346\264\201/\344\275\234\344\270\232/2-23.\347\273\237\350\256\241\344\270\252\346\225\260\344\275\234\344\270\232/work.js" new file mode 100644 index 0000000000000000000000000000000000000000..a03381d6e5b1baa400aecb22d3b5e4a200aeed95 --- /dev/null +++ "b/\345\255\243\351\233\250\346\264\201/\344\275\234\344\270\232/2-23.\347\273\237\350\256\241\344\270\252\346\225\260\344\275\234\344\270\232/work.js" @@ -0,0 +1,28 @@ +//作业:实现分页,能实现男女个数和总数的统计,能统计出(小于等于18) 和 +//18-45 和 45岁以上的人数(可以的话一条sql,分组,使用占位符的形式去写) + +let mysql=require("mysql"); +let con = mysql.createConnection({ + host: "localhost", + user: "root", + password: "root", + port: "3306", + database: "user" +}); +con.connect(); + +function way(){ + let waysql1="SELECT count(1) AS '<18' FROM `user` where age<18 "; + let waysql2="SELECT count(1) AS '>45' FROM `user` where age>45 "; + let waysql3='SELECT count(1) AS "18~45" FROM `user` where age>18 and age<45 '; + let waysql4='SELECT sex,count(1) as "数量",(SELECT COUNT(1) FROM `user`) as"总数" FROM `user` GROUP BY sex ;'; + + + con.query(waysql4, (err, data) => { + console.log(err); + console.log(data); + }); +} +way(); + +con.end() \ No newline at end of file