我正在编写一个项目报告,该报告需要来自单个表的一些棘手的输出。
这是名为:daily_visit_expenses的表的结构
有这样的数据::
现在我想要的输出是这三个查询在单个列(任何名称)中的组合,查询是:
SELECT DISTINCT(`cust_1`) FROM `daily_visit_expenses` WHERE user='sanjay' AND `purpose_1`='Sales'
SELECT DISTINCT(`cust_2`) FROM `daily_visit_expenses` WHERE user='sanjay' AND `purpose_2`='Sales'
SELECT DISTINCT(`cust_3`) FROM `daily_visit_expenses` WHERE user='sanjay' AND `purpose_3`='Sales'
我想从单个查询中获取输出,该查询是上述三个查询在单个列中的组合,customers
例如DISTINCT
.
SQL 导出:
CREATE TABLE IF NOT EXISTS `daily_visit_expenses` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user` varchar(255) NOT NULL,
`date` date NOT NULL,
`status` varchar(50) NOT NULL,
`location` varchar(50) NOT NULL,
`cust_1` varchar(255) NOT NULL,
`cust_2` varchar(255) NOT NULL,
`cust_3` text NOT NULL,
`cust_4` text NOT NULL,
`purpose_1` varchar(20) NOT NULL,
`purpose_2` varchar(20) NOT NULL,
`purpose_3` varchar(20) NOT NULL,
`purpose_4` varchar(20) NOT NULL,
`visit_type` varchar(20) NOT NULL,
`expenses` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
INSERT INTO `daily_visit_expenses` (`id`, `user`, `date`, `status`, `location`, `cust_1`, `cust_2`, `cust_3`, `cust_4`, `purpose_1`, `purpose_2`, `purpose_3`, `purpose_4`, `visit_type`, `expenses`) VALUES
(5, 'sanjay', '2012-06-15', 'Working', 'Customer', 'S.G.R.S. Chemical & Minral Industries', '', 'fatehpur foundry', '', 'Sales', '', 'Sales', '', 'Outstation', 2323),
(8, 'sanjay', '2012-06-25', 'Working', 'Office', '', '', '', '', '', '', '', '', '', 0),
(9, 'sanjay', '2012-06-09', 'Working', 'Office', '', '', '', '', '', '', '', '', '', 0),
(10, 'sanjay', '2012-06-05', 'Working', 'Customer', 'V.N INTERNATIONAL', 'G.SURGIWEAR', '', '', 'Sales', 'Sales', '', '', 'Outstation', 332),
(11, 'sanjay', '2012-06-30', 'Working', 'Customer', 'Ganesh Plywood-Sitapur', '', '', '', 'Service', '', '', '', 'Outstation', 434),
(12, 'sanjay', '2012-06-04', 'Absent', '', '', '', '', '', '', '', '', '', '', 0),
(13, 'sanjay', '2012-06-06', 'Absent', '', '', '', '', '', '', '', '', '', '', 0),
(14, 'sanjay', '2012-06-08', 'Leave', '', '', '', '', '', '', '', '', '', '', 0);