gpt4 book ai didi

sql - 我如何创建这个复杂的查询?

转载 作者:搜寻专家 更新时间:2023-10-30 23:23:21 25 4
gpt4 key购买 nike

我有 3 个表:projects、skills 和 project_skills。在项目表中,我持有项目的一般数据。第二个表技能我持有技能 ID 和技能名称我也有 projects_skills 表,它是持有项目的技能关系。这是表的方案:

CREATE TABLE IF NOT EXISTS `project_skills` (
`project_id` int(11) NOT NULL,
`skill_id` int(11) NOT NULL,
KEY `project_id` (`project_id`),
KEY `skill_id` (`skill_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;


CREATE TABLE IF NOT EXISTS `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`employer_id` int(11) NOT NULL,
`project_title` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`project_description` text COLLATE utf8_turkish_ci NOT NULL,
`project_budget` int(11) NOT NULL,
`project_allowedtime` int(11) NOT NULL,
`project_deadline` datetime NOT NULL,
`total_bids` int(11) NOT NULL,
`average_bid` int(11) NOT NULL,
`created` datetime NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `created` (`created`),
KEY `employer_id` (`employer_id`),
KEY `active` (`active`),
FULLTEXT KEY `project_title` (`project_title`,`project_description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=3 ;

CREATE TABLE IF NOT EXISTS `skills` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` int(11) NOT NULL,
`name` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`seo_name` varchar(100) COLLATE utf8_turkish_ci NOT NULL,
`total_projects` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `seo_name` (`seo_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=224 ;

我想选择具有相关技能名称的项目。我想我必须使用 JOIN 但我不知道该怎么做。谢谢

最佳答案

听起来 JOIN 是完全正确的:

SELECT ...
FROM projects
INNER JOIN project_skills ON (project_skills.project_id = projects.id)
INNER JOIN skills ON (skills.id = project_skills.skill_id)

关于sql - 我如何创建这个复杂的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2980769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com