【发布时间】:2020-03-14 18:13:29
【问题描述】:
我有一个表格,其中包含身高、体重和学生日期 (sid)。 height 和 weight 包含在同一列中:'Percent' 并且枚举列包含高度和重量。
两者的条目具有完全相同的日期:
-- Table structure and sample data for table `PROGWandH`
--
CREATE TABLE `wandh` (
`Wid` int(24) NOT NULL,
`sid` int(4) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`level` enum('height','weight') NOT NULL,
`Percent` decimal(5,1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `PROGWandH` (`Wid`, `sid`, `date`, `level`, `Percent`) VALUES
(157, 55, '2020-01-13 15:00:00', 'weight', '20.2'),
(131, 55, '2019-12-12 15:00:00', 'weight', '19.8'),
(121, 55, '2019-11-14 15:00:00', 'weight', '19.3'),
(774, 55, '2020-01-13 15:00:00', 'height', '113.0'),
(749, 55, '2019-12-12 15:00:00', 'height', '112.0'),
(739, 55, '2019-11-14 15:00:00', 'height', '111.5');
--
ALTER TABLE `wandh`
ADD PRIMARY KEY (`Wid`);
我正在尝试生成一个包含列高、宽度和日期的列表。我使用的 PHP 一个接一个地生成一组,但我需要生成列表为身高、体重、日期、身高、体重等。 到目前为止我尝试过的会产生重复,因此输出不会同步:
select Percent, s1.Percent1, date
from wandh
JOIN (SELECT DISTINCT Percent as 'Percent1' from wandh where level = 'weight' and sid = 55) as s1
where sid = 55 and level = 'height';
和
select Percent, s1.Percent1, date
from wandh JOIN (SELECT Percent as 'Percent1' from wandh where level = 'weight' and sid = 55) as s1
on date where sid = 55 and level = 'height';
我尝试过的其他变体不起作用。
select level, Percent, date from wandh where level like '%eight' and sid = 55;
我错过了什么?
【问题讨论】:
标签: mysql