Mysql中用了left join查询时候数据变多,在线等
SELECTpassenger_name,order_typeFROMtb_sell_tbfinanceLEFTJOIN(#计算成人人数SELECTtb_sell_tbf...
SELECT passenger_name, order_type FROM tb_sell_tbfinance LEFT JOIN (#计算成人人数 SELECT tb_sell_tbfinance.order_no AS order_no0, tb_sell_tbfinance.passenger_type AS passenger_type0, COUNT(*) AS passenger_count FROM tb_sell_tbfinance GROUP BY tb_sell_tbfinance.passenger_type, tb_sell_tbfinance.order_no ) AS order_detail ON (tb_sell_tbfinance.order_no = order_detail.order_no0);比下面的多了5条重复数据,看不懂了 SELECT passenger_name, order_type FROM tb_sell_tbfinance;
展开
展开全部
(#计算成人人数
SELECT tb_sell_tbfinance.order_no AS order_no0,
tb_sell_tbfinance.passenger_type AS passenger_type0,
COUNT(*) AS passenger_count
FROM tb_sell_tbfinance
GROUP BY tb_sell_tbfinance.passenger_type, tb_sell_tbfinance.order_no) AS order_detail 中要保证一个order_no0只能有至多一笔数据,若有超过一笔的话left outer join 会导致数据比tb_sell_tbfinance中数据多
SELECT tb_sell_tbfinance.order_no AS order_no0,
tb_sell_tbfinance.passenger_type AS passenger_type0,
COUNT(*) AS passenger_count
FROM tb_sell_tbfinance
GROUP BY tb_sell_tbfinance.passenger_type, tb_sell_tbfinance.order_no) AS order_detail 中要保证一个order_no0只能有至多一笔数据,若有超过一笔的话left outer join 会导致数据比tb_sell_tbfinance中数据多
展开全部
A left join B on A.x = B.y 重复,是因为 在B表中 A 和 B join的条件 不是唯一的,有重复,重复几条,就会多几条
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。
追问
SELECT
passenger_name,
order_type
FROM
tb_sell_tbfinance
这个左表里只有37行数据
追答
你检查一下你左表与右表关联的条件,应该就是这些细节问题导致的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询