首页 > 数据库技术 > 详细

sql草稿

时间:2019-11-03 20:45:43      阅读:73      评论:0      收藏:0      [点我收藏+]
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) 

 

sql草稿

原文:https://www.cnblogs.com/flypig666/p/11788889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!