1、利用內聯關系取出多組條數據最新的數據(即oracle的row_number概念):
-- 篩選出的狀態 inner join篩選出來的狀態值 select t.flow_id,t.job_id,t.`status`,t.start_time from ( SELECT flow_id,job_id,status,start_time,max(FROM_UNIXTIME(start_time/1000)) as max_start_time from execution_jobs -- where (flow_id='end_it_sda' or flow_id='end_paasjszb_sda') where (flow_id='end_paasjszb_sda') and start_time>1544976295990 -- and job_id like '%sda%' group by job_id,status ) t,( --內聯用例 SELECT flow_id,job_id,`status`,start_time,max(FROM_UNIXTIME(start_time/1000)) as max_start_time from execution_jobs -- where (flow_id='end_it_sda' or flow_id='end_paasjszb_sda') where (flow_id='end_paasjszb_sda') and start_time>1544976295990 -- and job_id='it_sda01_jiraissue' group by job_id ) t1 where t1.max_start_time=t.max_start_time and t1.job_id=t.job_id
2、按照分區來查mysql數據: select etl_tx_dt ,count(*) from zcfw_sda.sda01_core_asset_bad_out_info group by etl_tx_dt ; 3、啟動django項目命令:django-admin startproject HelloWorld 4、通過分組確定唯一標識: select count(*),core_lend_request_id,lend_contract_code,loan_time from datawindow_dw.finance_report_defferred_income_detail_2 where etl_tx_dt=20181208 group by core_lend_request_id,lend_contract_code,loan_time having count(*)>1; 5、分組按照日期排序: select etl_tx_dt ,count(*) from hhpt_sda.sda01_btows_batch_mobile_20181210 group by etl_tx_dt order by etl_tx_dt desc; 6、數據庫操作: (1)模糊匹配查找出表execution_jobs下flow_id有sda名字的 SELECT distinct flow_id from execution_jobs where execution_jobs.flow_id like 'sda%'; (2)模糊匹配查找出表projects下有sda_pro名字並且active=1的所有信息 select * from projects p where p.active = 1 and p.name like '%sda_pro'; (3)從表execution_jobs找出10個時間戳為秒級別的從大到小的排序 select FROM_UNIXTIME(el.start_time/1000),el.* from execution_jobs el order by FROM_UNIXTIME(el.start_time/1000) desc limit 10 (4)從表execution_jobs找出時間戳大於2018-12-12的所有信息 select FROM_UNIXTIME(el.start_time/1000),el.* from execution_jobs el where FROM_UNIXTIME(el.start_time/1000) > '2018-12-12' (5)統計表execution_jobs中時間戳大於2018-12-12的條數 select count(*) from execution_jobs el where FROM_UNIXTIME(el.start_time/1000) > '2018-12-12'; (6)從表projects中找出時間戳大於2018-12-12,active=1和name中有sda_pro的任務列表,其中匹配條件為表project的id等於表execution_jobs的id select p.`name`,el.job_id from projects p,execution_jobs el where p.active = 1 and p.name like '%sda_pro' and p.id = el.project_id and FROM_UNIXTIME(el.start_time/1000) > '2018-12-12' group by p.`name`,el.job_id order by p.`name`,el.job_id; (7)從表projects中找出時間戳大於2018-12-12,active=1和name中有sda_pro,並且execution_jobs表中job_id也有sda_pro的任務列表,其中匹配條件
為表project的id等於表execution_jobs的id select p.`name`,el.job_id from projects p,execution_jobs el where p.active = 1 and p.name like '%sda_pro' and p.id = el.project_id and FROM_UNIXTIME(el.start_time/1000) > '2018-12-12' and el.job_id like '%sda%' group by p.`name`,el.job_id order by p.`name`,el.job_id; 7、時間戳與日期的相互轉換: -- 時間戳轉換成時間格式 select FROM_UNIXTIME(1544991635000/1000) -- 日期轉換成時間戳 SELECT UNIX_TIMESTAMP('2018-12-22 00:00:00') *1000