mysql

How to create a MySQL hierarchical recursive query?

旧巷老猫 提交于 2021-02-17 07:05:12
问题 I have a MySQL table which is as follows: id name parent_id 19 category1 0 20 category2 19 21 category3 20 22 category4 21 ... ... ... Now, I want to have a single MySQL query to which I simply supply the id [for instance say id=19 ] then I should get all its child ids [i.e. result should have ids '20,21,22'].... The hierarchy of the children is not known; it can vary.... I know how to do it using a for loop... but how to achieve the same using a single MySQL query? 回答1: For MySQL 8+: use the

How to give permission to other PC to add data to my database in MySQL.in my computer

强颜欢笑 提交于 2021-02-17 07:03:26
问题 I made a python program here and i wanted to send the code to my friend and he was unable to add values through the program to my database, is there a way i can allow his access. Code: from tkinter import * import mysql.connector as mysql root = Tk() def flush(*args): name = nme.get() phone = ph.get() emirate = e_id.get() con = mysql.connect(host='127.0.0.1', user='root', password='monkey123', database='NZ') c = con.cursor() c.execute("Insert into gliy VALUES ('"+name+"','"+str(phone)+"','"

3. 关于sql注入的综合题

笑着哭i 提交于 2021-02-17 06:58:40
关于sql注入的综合题 ----------南京邮电大学ctf : http://cms.nuptzj.cn/ 页面上也给了好多信息: 根据这个sm.txt , 我们可以得到好多消息, config.php :存放数据库信息,移植此CMS时要修改 index.php :主页文件 passencode.php :Funny公司自写密码加密算法库 say.php :用于接收和处理用户留言请求 sm.txt :本CMS的说明文档 sae的information_schema表好像没法检索,我在这里给出admin表结构 create table admin ( id integer, username text, userpass text, ),表名 : admin 字段名 : username , userpass 而且当我们看到这个url : http://cms.nuptzj.cn/about.php?file=sm.txt 我们可以感受到文件包含的气息 。具体操作步骤在我上一篇博客中:http://www.cnblogs.com/bmjoker/p/8877336.html,我们尝试输入 http://cms.nuptzj.cn/about.php?file=php://filter/read=convert.base64-encode/resource=antiinject

Sum rows from different conditions in Mysql

爷,独闯天下 提交于 2021-02-17 06:57:09
问题 The original table is large so I will simplify it: mytable: CONDITION SIZE 1 10 9 10 9 10 1 20 9 20 1 20 1 30 With a query similar to SELECT CASE WHEN CONDITION=1 THEN 'OK' ELSE 'BAD' END AS Status, SUM (CASE WHEN SIZE=10 THEN 1 ELSE 0 END) AS Small, SUM (CASE WHEN SIZE=20 THEN 1 ELSE 0 END) AS Medium, SUM (CASE WHEN SIZE=30 THEN 1 ELSE 0 END) AS Large, FROM mytable GROUP BY Status Then we have this result Status Small Medium Large OK 1 2 1 BAD 2 1 0 What is the proper code to get: Status

Feed流系统设计

六眼飞鱼酱① 提交于 2021-02-17 06:56:58
点击上方蓝色“ 肉眼品世界 ”,选择“设为星标” 来源 :r6d.cn/E8pb 差不多十年前,随着功能机的淘汰和智能机的普及,互联网开始进入移动互联网时代,最具代表性的产品就是微博、微信,以及后来的今日头条、快手等。这些移动化联网时代的新产品在过去几年间借着智能手机的风高速成长。 简介 差不多十年前,随着功能机的淘汰和智能机的普及,互联网开始进入移动互联网时代,最具代表性的产品就是微博、微信,以及后来的今日头条、快手等。这些移动化联网时代的新产品在过去几年间借着智能手机的风高速成长。 这些产品都是Feed流类型产品,由于Feed流一般是按照时间“从上往下流动”,非常适合在移动设备端浏览,最终这一类应用就脱颖而出,迅速抢占了上一代产品的市场空间。 Feed流是Feed + 流,Feed的本意是饲料,Feed流的本意就是有人一直在往一个地方投递新鲜的饲料,如果需要饲料,只需要盯着投递点就可以了,这样就能源源不断获取到新鲜的饲料。在信息学里面,Feed其实是一个信息单元,比如一条朋友圈状态、一条微博、一条咨询或一条短视频等,所以Feed流就是不停更新的信息单元,只要关注某些发布者就能获取到源源不断的新鲜信息,我们的用户也就可以在移动设备上逐条去浏览这些信息单元。 当前最流行的Feed流产品有微博、微信朋友圈、头条的资讯推荐、快手抖音的视频推荐等,还有一些变种,比如私信、通知等

MySQL Select rows that from table01 that doesn't exist on table02 [duplicate]

廉价感情. 提交于 2021-02-17 06:55:26
问题 This question already has answers here : Find records from one table which don't exist in another (8 answers) Closed 10 months ago . I have two tables, table03 have 10 rows and table01 have 21 rows, now I want to get rows from table03 where they don't exist in table01, so far I wrote this query but it shows all rows of table03 even some rows doesn't exist on table01. SELECT T3.`DateAdded`, T3.`Query_name`, T3.`Fund`, T3.`Ticker` FROM `table_name03` T3 LEFT JOIN `table_name01` T1 ON T3.

mysql user variable assignement with count(*)

落爺英雄遲暮 提交于 2021-02-17 06:54:19
问题 I try to do query with a user variable, but I don't understand why, i can't update the variable in the query. I want to sum the grouped result for each day to do a chart. That really simple. SET @total := 0; SELECT "total Register", li.registerDate, @total := COUNT(*) + @total as registerNumber, @total FROM calendar c3 INNER JOIN ( SELECT c2.ide_calendar as ide_calendar, c2.name, DATE_FORMAT(i.date_creation, "%Y-%m-%d") as registerDate FROM calendrar c2 LEFT JOIN inscription i ON i.ide

insert in select in MySQL with JDBC

不想你离开。 提交于 2021-02-17 06:54:05
问题 I would like to have a value from a row inserted into an other row here is my code: static void addVipMonth(String name) throws SQLException { Connection conn = (Connection) DriverManager.getConnection(url, user, pass); PreparedStatement queryStatement = (PreparedStatement) conn.prepareStatement("INSERT INTO vips(memberId, gotten, expires) " + "VALUES (SELECT name FROM members WHERE id = ?, NOW(), DATEADD(month, 1, NOW()))"); //Put your query in the quotes queryStatement.setString(1, name);

How to get data from parent and child table on the basis of status where foreign key have different status for every row

此生再无相见时 提交于 2021-02-17 06:52:18
问题 I have 2 tables with foreign key relationship. Situation is I have a case and a case have many revision s and every revision have its own status . I want to get parent table data and child data if only specific row of foreign key table status is changed Table Case id case_no patient_name age 1 12564 abc 78 2 1256 lkj 63 3 125 bdhf 23 Table Case_Revisons id case_id revison status 1 1 0 assesemnt 2 1 1 assesment 3 1 2 treatment 4 2 2 assesment 5 3 1 assesment What I want is all data all data

trigger mysql unknown table

强颜欢笑 提交于 2021-02-17 06:34:25
问题 I've been trying to solve this problem. Here is the code: CREATE TRIGGER some_trigger AFTER UPDATE ON table_a FOR EACH ROW BEGIN DECLARE tname VARCHAR(20); IF (table_a.field_offer=1) THEN SET tname='table_b'; ELSEIF (table_a.field_offer=0) THEN SET tname='table_c'; END IF; IF ((new.field_state = 0)) THEN UPDATE tname join table_a on tname.ID=table_a.ref_field SET tname.STOCK = tname.STOCK -1; ELSEIF ((new.field_state = 1)) THEN UPDATE tname join table_a on tname.ID=table_a.ref_field SET tname