嗨,我有这样的 mysql 表:
.poll_users
(id int(11) NOT NULL AUTO_INCREMENT
name VARCHAR(255) NOT NULL
PRIMARY KEY (id))
.poll_referendum
(id int(11) NOT NULL AUTO_INCREMENT
name varchar(255) DEFAULT NULL
PRIMARY KEY (id))
.poll_questions
id int(11) NOT NULL AUTO_INCREMENT
referendum_id int(11) DEFAULT NULL
body varchar(255) DEFAULT NULL
created_at datetime DEFAULT NULL
updated_at datetime DEFAULT NULL
PRIMARY KEY (`id`)
KEY `referendum_id` (`referendum_id`))
.poll_answers
`id` int(11) NOT NULL AUTO_INCREMENT
`vote_id` int(11) DEFAULT '0'
`question_id` int(11) NOT NULL
`created_at` datetime DEFAULT NULL
`updated_at` datetime DEFAULT NULL
PRIMARY KEY (`id`)
KEY `vote_id` (`vote_id`)
KEY `question_id` (`question_id`))
.poll_voting
`id` int(11) NOT NULL AUTO_INCREMENT
`question_id` int(11) NOT NULL DEFAULT '0'
`answer_id` int(11) NOT NULL DEFAULT '0'
`user_id` int(11) NOT NULL DEFAULT '0'
`created_at` datetime DEFAULT NULL
`updated_at` datetime DEFAULT NULL
PRIMARY KEY (`id`)
KEY `question_id` (`question_id`)
KEY `answer_id` (`answer_id`)
KEY `user_id` (`user_id`))
.vote_types
`id` int(11) NOT NULL AUTO_INCREMENT
`type` varchar(255) DEFAULT NULL
PRIMARY KEY (`id`))
如何获取 vote_types 表中的投票类型并对应于正确的问题和调查?
我试过了:SELECT vote_id FROM surveys.poll_answers WHERE question_id = 1;
但这给了我:
和 1,2 是投票类型文本SELECT *
FROM
调查的索引.
vote_types
WHERE
id=1
在 poll_answers 表中,我保留索引哪些投票类型分配给问题,问题分配给 poll_referendum 表中的适当公投,所以我如何获取与正确问题相对应的投票类型和像这样的调查
SELECT vote_id indexes from poll_answers table and they index to vote_types where are stored vote types in text and those vote_types corresponds to proper questions that are stored in poll_questions and referendums that are stored in poll_referendum ?
谢谢你的帮助