我正在尝试创建一个时间表,显示公司的状态和工作,我有两个单独的表:
<!DOCTYPE html>
<html lang="en-us" ng-app='name'>
<head>
<script src="//code.angularjs.org/1.5.0-rc.1/angular.js"></script>
<script src="controller.js"></script>
</head>
<body >
<h ng-controller="Login">{{ someVar }}</h>
</body>
</html>
和Jobs
两个表都与列号不匹配,所以我不能使用union all(据我所知)。我怎样才能做我想做的事?
工作:
Statuses
状态表
CREATE TABLE `jobs` (
`job_id` int(11) NOT NULL,
`job_company` int(11) NOT NULL,
`job_user` int(100) NOT NULL,
`job_name` varchar(100) NOT NULL,
`job_description` text NOT NULL,
`job_duration` int(11) NOT NULL,
`job_category` varchar(250) NOT NULL,
`job_employer` varchar(100) NOT NULL,
`job_enabled` int(2) NOT NULL DEFAULT '1',
`job_startdate` date NOT NULL,
`job_enddate` date NOT NULL,
`job_wage_type` varchar(15) NOT NULL,
`job_wage` decimal(13,2) NOT NULL,
`job_requirements` varchar(255) NOT NULL,
`job_application_start` date NOT NULL,
`job_application_end` date NOT NULL,
`job_experience` varchar(255) NOT NULL,
`job_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`job_live` varchar(10) NOT NULL,
`job_address_name` varchar(100) NOT NULL,
`job_address_street` varchar(100) NOT NULL,
`job_address_city` varchar(100) NOT NULL,
`job_address_zip` varchar(15) NOT NULL,
`job_country` varchar(100) NOT NULL,
`job_address_lat` varchar(50) NOT NULL,
`job_address_long` varchar(50) NOT NULL,
`job_address_differs` int(11) NOT NULL,
`job_type` varchar(15) NOT NULL,
`job_featured` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `jobs`
--
INSERT INTO `jobs` (`job_id`, `job_company`, `job_user`, `job_name`, `job_description`, `job_duration`, `job_category`, `job_employer`, `job_enabled`, `job_startdate`, `job_enddate`, `job_wage_type`, `job_wage`, `job_requirements`, `job_application_start`, `job_application_end`, `job_experience`, `job_date`, `job_live`, `job_address_name`, `job_address_street`, `job_address_city`, `job_address_zip`, `job_country`, `job_address_lat`, `job_address_long`, `job_address_differs`, `job_type`, `job_featured`) VALUES
(26, 1, 29, 'Senior Web developer', 'Test', 1, 'CEO & General Management;Information & Communication Technology', '1', 0, '2016-04-07', '2017-06-11', 'weekly', '12.50', '1', '2016-03-31', '2016-05-19', '2', '2016-03-31 06:07:19', 'live', 'london', 'london', 'london', 'london', 'United Kingdom', '51.4654277', '-0.2547461', 0, 'fulltime', NULL),
我想要完成的是在一个时间轴中合并它,在一个随机组织中,我可以做2个foreach,但这意味着一个将在顶部,另一个在底部。
这有可能吗?
答案 0 :(得分:0)
此单个查询将生成包含作业和状态行数据的一行。每个timeline_status
这应该使你的foreach循环更容易处理,而不是让两个单独的结果保持一致,你只需要在job_id中查找更改,以了解该行何时与下一个作业相关。
SELECT j.*, s.*
FROM jobs j
JOIN timeline_status as s ON s.timeline_status_user = j.job_user
ORDER BY j.job_id
当然,如果您将select限制为您实际想要在以下处理中使用的列,那么查询会更有效。