码迷,mamicode.com
首页 > 数据库 > 详细

mysql 练习题

时间:2020-07-22 20:30:52      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:spl   show   sele   习题   onclick   play   lap   mamicode   sel   

 

技术图片

 

技术图片
 1 with temp1 as (
 2 select 1 as id ,111 as barCode,A1 name  union 
 3 select 2 as id ,112 as barCode,A2 name union 
 4 select 3 as id ,200 as barCode,B1 name union 
 5 select 4 as id ,230 as barCode,B2 name union 
 6 select 5 as id ,140 as barCode,B3 name 
 7 ), temp2 as (
 8 select 1 as id ,112 as barCode,10 as Amount,2013-10-20 Dates  union 
 9 select 2 as id ,112 as barCode,20 as Amount,2013-12-20 Dates union 
10 select 3 as id ,200 as barCode,25 as Amount,2014-01-08 Dates union 
11 select 4 as id ,230 as barCode,30 as Amount,2014-03-15 Dates union 
12 select 5 as id ,112 as barCode,40 as Amount,2014-08-7 Dates union
13 select 5 as id ,230 as barCode,70 as Amount,2014-09-01 Dates 
14 
15 )
16 
17 
18 
19 
20 /*
21 select t2.barCode,t1.name,t2.Amount,t2.dates
22 from temp2 t2 inner join temp1 t1 on t2.barCode=t1.barCode
23 where t1.name like ‘B%‘ and DATES >‘2014-01-01‘ ;
24 */
25 
26 /*
27 select  t2.barCode,t1.name,sum(t2.amount) cnt
28 from temp2 t2 left  join temp1 t1 on t2.barCode=t1.barCode
29 group by t2.barcode
30 */
31 
32 /*
33 select  t2.barCode,t1.name,count(1) cnt
34 from temp2 t2 left  join temp1 t1 on t2.barCode=t1.barCode
35 group by t2.barcode
36 having count(t2.barCode)>1
37 */
View Code

 

技术图片

 

 技术图片

 

 技术图片

 

mysql 练习题

标签:spl   show   sele   习题   onclick   play   lap   mamicode   sel   

原文地址:https://www.cnblogs.com/linbo3168/p/13362593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!