Beg sql sentence, kneel beg online and so on!

1. There are tested items in the project, but there is a package in the test project, which is a small collection of individual items
2. Now the database is designed, but the sql is poor. Ask for help

  • item list
CREATE TABLE tx_detection ( 
    id int  UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY COMMENT "ID",
    is_list tinyint unsigned not null default 0 comment "0 1",
    pid enum("a","b","c","d","e")   not null comment "ID",
    cid varchar(32) not null default "" comment "id",
    title CHAR(22) NOT NULL DEFAULT "" COMMENT "",
    description CHAR(50) NOT NULL DEFAULT "" COMMENT "",
    content VARCHAR(10000) COMMENT "",
    status TINYINT(1) NOT NULL DEFAULT "1" COMMENT "1  0 ",
    sort int unsigned not null default 0 comment "",
    index(pid)--enum 
) ENGINE=MyISAM CHARACTER SET utf8;
  • sql statement
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (1, 0, "b", "", "1", "", "1", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (2, 0, "b", "", "2", "", "2", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (3, 0, "b", "", "1", "", "3", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (4, 0, "d", "", "4", "4", "4", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (5, 0, "a", "", "5", "5", "5", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (6, 0, "a", "", "6", "6", "6", 1, 0);
INSERT INTO `tx_detection`(`id`, `is_list`, `pid`, `cid`, `title`, `description`, `content`, `status`, `sort`) VALUES (7, 1, "b", "1,3", "A", "A", "A", 1, 0);
  • self-written statements
SELECT a.* from tx_detection as a,tx_detection as b where a.id in (select cid from tx_detection where tx_detection.id = 7)  and a.id = 7; --
SELECT a.* from tx_detection as a,tx_detection as b where a.id in (1,3)  and a.id = 7;--vachar  

 
SELECT a.* from tx_detection as a where a.id in (1,3);
SELECT a.* from tx_detection as a where a.id in (select cid from tx_detection where id = 7);1 vacharwhere id = 7 


SELECT a.* from tx_detection as a,tx_detection as b where a.id in (select cid from tx_detection where id = 7)  and b.id = 7;
  vachar in(1,3)aa.id = 7

add 3 because I see other people say that in ("1pm, no. 3") this is OK. I can also look it up myself. I can really query it

.
SELECT a.* from tx_detection as a,tx_detection as b where a.id in ("1","3")  and b.id = 7;

then the vachar in the data is changed to the form of "1percent and 3percent".

3. cID cid vachar
4.
id=7 1,3

Aug.18,2021

A (normal result):
clipboard.png

BSQL:
clipboard.png
AB
select cid from tx_detection where id = 7(1,3)('1,3')
in(1,3)

clipboard.png

('1,3')

clipboard.png

mysqltx_detectionidAid=13Bid='1,3'
mysqlintint'1,3'mysql:

clipboard.png

in the same way, the above '1jue 3' has been converted into int 1 by mysql, which returns the row record of id=1.
can't be written any more. It's a bit verbose. To get the correct result is to use the find_in_set function

.

sql

SELECT a.* FROM tx_detection a, (SELECT id, cid FROM tx_detection WHERE id = 7) b WHERE FIND_IN_SET (a.id, b.cid) OR a.id = 7

Note that instead of "1", "3", "3" is used for cid.

for the questions you mentioned later, you should pay attention to the different types, at least id in (b.cid) instead of putting the results of select directly into

.
SELECT
    *
FROM
    tx_detection
WHERE
    (id = 4)
OR id IN (
    SELECT
        substring_index(
            substring_index(
                a.cid,
                ',',
                b.help_topic_id + 1
            ),
            ',' ,- 1
        )
    FROM
        tx_detection AS a
    JOIN mysql.help_topic b ON b.help_topic_id < (
        length(a.cid) - length(REPLACE(a.cid, ',', '')) + 1
    )
    WHERE
        a.id = 4
);

this is an answer from a friend

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3100e-2bd64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3100e-2bd64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?