SELECT count(*) FROM `t_product_base`
select m_name from t_medicinal_info where id in (select t_medicinal_id from t_medicinal_productbase where t_product_base_id = ‘2af213b02cef481b8432fd5b0d753896‘)
select * from t_product_base t_medicinal_productbase t_medicinal_info where t_medicinal_productbase=‘2af213b02cef481b8432fd5b0d753896‘ and t_medicinal_info.id=t_medicinal_productbase.t_medicinal_id
--查询有标明药材的公司
Set @i:=0;
select (@i:=@i+1) i,b.id,GROUP_CONCAT(a.m_name SEPARATOR‘ ‘) as medicinalNames,b.b_name,b.b_Position,b.b_area,b.b_water_environment,b.b_soil_environment,b.b_air_environment,b.b_totality_appraise,b.b_remarks from t_medicinal_info a, t_product_base b, t_medicinal_productbase c where (a.id=c.t_medicinal_id and b.id=c.t_product_base_id) group by b.b_create_time
select count(*) from t_product_base a,t_medicinal_productbase b where a.id=b.t_product_base_id
--查询无表明药材的公司,使用带exists的嵌套查询
Set @i:=0;
select (@i:=@i+1) j,a.* from t_product_base a where not exists(select * from t_medicinal_productbase b where a.id=b.t_product_base_id)
Set @j:=0;
select (@j:=@j+1) j from t_medicinal_info a, t_product_base b, t_medicinal_productbase c where (a.id=c.t_medicinal_id and b.id=c.t_product_base_id)
select count(*) from t_medicinal_info a, t_product_base b, t_medicinal_productbase c where (a.id=c.t_medicinal_id and b.id=c.t_product_base_id)
原文:https://www.cnblogs.com/flypig666/p/11788889.html