Mysql-經典語句收集

一、求兩個日期間的天數sql

-- fucarry中一條記錄有兩個合約,求該條記錄這兩個合約到期日的相差天數
select a.futu_code,
      datediff((select expire_date 
         from hs_user.ptfutucode b where a.exchange_type = b.exchange_type
          and a.futu_code = b.futu_code),(select expire_date 
         from hs_user.ptfutucode b where a.exchange_type = b.exchange_type
          and a.second_code = b.futu_code)) as diff_date
 from hs_futu.fucarry a;

一、delete中的子查詢(刪除tableA中)code

delete a
  from tableA a, tableB b
 where a.column = b.column;
相關文章
相關標籤/搜索