1.專案中有 檢測的專案 但是檢測專案中有 套餐, 套餐算是 單個專案的小集合
2.現在資料庫設計出來了,但是奈何sql差,求幫忙
專案表
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陳述句
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);
自己寫的陳述句
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 我在想應該是自己vachar欄位的這樣寫法是不對的,但是還一個問題就是最后加上限制where 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)就可以了,那么這個資料結構該怎么改呢,還有就是因為查詢a的資料所以a.id = 7了肯定不行,所以第一次補充的時候出錯能理解了
補充3 因為我看別人說in('1','3')這樣是可以的我自己也是了下確實可以查詢到
SELECT a.* from tx_detection as a,tx_detection as b where a.id in ('1','3') and b.id = 7;
那么資料中vachar 改成 '1','3'這種形式呢。

3.自己寫的確實不行啊 ,我想的是先插入c子ID的資料 然后自己查詢自己,奈何不對 感覺自己的 cid 這個用vachar是個錯誤的選擇。
4.想實作的效果
查詢id=7的時候 把1,3也給查詢出來。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/80882.html
標籤:非技術區
下一篇:MHA部署問題
