Mysql Sql来获取行中的列值

Mysql Sql来获取行中的列值,mysql,select,left-join,Mysql,Select,Left Join,我有一张表格,上面有日期、系统、硬度、导电性、罐号 date system cond hard tankno 2014-01-04 HT 55.67 2.68 1 2014-01-05 HT 64.67 3.1 2 2014-01-10 HT 54.77 2.44 1 2014-01-10 HT 66.3 3.47 2 2014-01-18 HT 55.63 2.38 1 2014-01-18

我有一张表格,上面有日期、系统、硬度、导电性、罐号

date system cond hard tankno 2014-01-04 HT 55.67 2.68 1 2014-01-05 HT 64.67 3.1 2 2014-01-10 HT 54.77 2.44 1 2014-01-10 HT 66.3 3.47 2 2014-01-18 HT 55.63 2.38 1 2014-01-18 HT 65.9 1.44 2 2014-01-24 HT 53.1 1.76 2 2014-01-28 HT 64.53 2.1 1 但此返回数据与tankno 1值可用的日期有关,如下所示:

Date system Tank 1 cond Tank1 Hard Tank 2 cond Tank 2hard 2014-01-04 HT 55.67 2.68 NULL NULL 2014-01-10 HT 54.77 2.44 66.3 3.47 2014-01-18 HT 55.63 2.38 65.9 1.44 2014-01-28 HT 64.53 2.1 NULL NULL 日期系统油箱1第二个油箱1硬油箱2第二个油箱2硬油箱 2014-01-04 HT 55.67 2.68空 2014-01-10 HT 54.77 2.44 66.3 3.47 2014-01-18 HT 55.63 2.38 65.9 1.44 2014-01-28 HT 64.53 2.1空 如何修改sql以获取所有日期的数据


我希望所有日期都来自日期列,并将其连接到所有坦克1的vlaues和坦克2的值

左连接仅适用于左侧的所有值,因此,如果左侧缺少值,则不会显示任何结果

您需要使用外部联接从两个岛获取值


外部连接不工作
select t1.date, t1.cond as tk1cond, t1.hard as tk1hard,
       t2.cond as tk2cond, t2.hard as tk2hard   
from systemvalue t1 left join systemavalue t2 
     on t1.date=t2.date 
     and t2.tankno='2' 
     and  t2.system='HT' 
     and month(t2.date)='01' 
     and year(t2.date)='2014' 
where t1.tankno='1' and t1.system='HT'
      and month(t1.date)='01' 
      and year(t1.date)='2014'
Date system Tank 1 cond Tank1 Hard Tank 2 cond Tank 2hard 2014-01-04 HT 55.67 2.68 NULL NULL 2014-01-10 HT 54.77 2.44 66.3 3.47 2014-01-18 HT 55.63 2.38 65.9 1.44 2014-01-28 HT 64.53 2.1 NULL NULL