sql 几个细节

===== 1: left outer join 

sql 中left outer join 时,如果左边的

 ===== 2: 在join中临时生成小表特别慢

在join中临时生成小表特别慢

SELECT
t.*
FROM
(
SELECT
*
FROM
tb_auction_trade_repeat
WHERE
shop_id IN (34189316, 58501945, 66588765)
) t
LEFT OUTER JOIN dim_auction a ON (t.auction_id = a.auction_id)
LEFT OUTER JOIN dim_shop s ON (t.shop_id = s.shop_id)
LEFT OUTER JOIN dim_thedate d ON (t.thedate = d.thedate)
LEFT OUTER JOIN (
SELECT
0 AS `is_trade_repeat`,
'新客户' AS `is_trade_repeat_name`
UNION ALL
SELECT
1 AS `is_trade_repeat`,
'老客户' AS `is_trade_repeat_name`
) re ON (
t.is_trade_repeat = re.is_trade_repeat
)

===== 3:不支持远程导出原始数据

不支持远程导出原始数据, select * from .... into outfile

 可以用dump导出sql数据.

但是可以通过某些工具帮助实现

=====4: outfile导出的文件是mysql用户名的

outfile导出的文件是mysql用户名的,所以要放在/tmp下面

=====5: join 小表 已知表可以用 case 来代替

====6:内连比left jion 要快很多


你可能感兴趣的:(sql 几个细节)