mysql分時查詢並求和

2021-09-27 13:16:12 字數 3505 閱讀 9530

為了防止自己忘記,也為了感謝幫助過我的人

select  

date_format(intime, '%y-%m-%d %h:00:00') as time,

sum(replace(num, '條', '')) as '分時數量'  

from factorymanager.warehouse 

where 

name = '掛鍍線' and right(num, 1) = '條' and   

to_days(now())-3 = to_days(intime)  

group by time

order by intime asc 

select  

intime  as time,

replace(num, 'kg', '') as '分時數量'  

from factorymanager.warehouse 

where 

name = '滾鍍線' and right(num, 2) = 'kg' and   

to_days(now())-3 = to_days(intime)  

group by time

order by intime asc 

select  

intime  as time,

replace(num, 'kg', '') as '分時數量'  

from factorymanager.warehouse 

where 

name = '貼片線' and right(num, 2) = 'kg' and   

to_days(now())-3 = to_days(intime)  

group by time

order by intime asc 

select  

sum(replace(num, 'kg', '') )as '時間段內數量'  

from factorymanager.warehouse 

where 

name = '滾鍍線' and right(num, 2) = 'kg' and   

intime > '2019-08-29 12:00:00' and intime < '2019-09-30 12:00:00'

order by intime asc 

select  

sum(replace(num, '條', '') )as '時間段內數量'  

from factorymanager.warehouse 

where 

name = '掛鍍線' and right(num, 1) = '條' and   

intime > '2019-08-29 12:00:00' and intime < '2019-09-30 12:00:00'

order by intime asc 

select  

sum(replace(num, 'kg', '') )as '時間段內數量'  

from factorymanager.warehouse 

where 

name = '貼片線' and right(num, 2) = 'kg' and   

intime > '2019-08-29 12:00:00' and intime < '2019-09-30 12:00:00'

order by intime asc 

除膠工位比較特殊,暫時不更改**

select     c.name as '製程名稱', 

e.positionid as '工位名稱', 

c.batch as '產品批號', 

e.uptime as '操作時間', 

c.type as '產品型別', 

c.costumer as '客戶名稱',

c.num as '產品數量' ,

e.employeename as '工作人員'

from factorymanager.product c, factorymanager.operationrecords e 

where 

c.serialid <> '-1-' and  

((e.positionid <> '除膠工位' and e.employeename = '劉必餘') or (e.positionid = '除膠工位' and e.partname03 = '劉必餘')) and 

e.uptime between '2019-09-27 18:56' and '2019-09-30 18:56' and locate(concat(c.batch, '#'), concat(e.productbatch,'#')) > 0 order by e.uptime asc

select     c.name as '製程名稱', 

e.positionid as '工位名稱', 

c.batch as '產品批號', 

e.uptime as '操作時間', 

c.type as '產品型別', 

c.costumer as '客戶名稱',

c.num as '產品數量' ,

e.partname03 as '工作人員'

from factorymanager.product c, factorymanager.operationrecords e 

where 

c.serialid <> '-1-' and  

e.positionid = '除膠工位'  and  e.partid01 = 'cj0001' and

e.uptime between '2019-09-27 18:56' and '2019-09-30 18:56' and locate(concat(c.batch, '#'), concat(e.productbatch,'#')) > 0 order by e.uptime asc

select     c.name as '製程名稱', 

e.positionid as '工位名稱', 

c.batch as '產品批號', 

e.uptime as '操作時間', 

c.type as '產品型別', 

c.costumer as '客戶名稱',

c.num as '產品數量' ,

e.employeename as '工作人員'

from factorymanager.product c, factorymanager.operationrecords e where 

c.serialid <> '-1-' and 

c.name = '掛鍍線' and

e.positionid = '掛鍍上料'    and

e.uptime between '2019-09-27 18:56' and '2019-09-30 18:56' 

and locate(concat(c.batch, '#'), concat(e.productbatch,'#')) > 0 

order by e.uptime asc

mysql求和 子查詢 MySQL子查詢

到現在為止,我們已經表明,以select宣告是乙個簡單的查詢。該單個語句從單個資料庫表中檢索資料。sql還同意建立乙個子查詢。即巢狀在其他查詢的查詢。下列實施例給出巢狀查詢。一種表示訂單資訊儲存,包含訂單號,客戶id。訂購日期。例如以下所看到的 一張表示儲存訂單物品資訊,例如以下 另一張表儲存的是客...

分時間段查詢

declare t table 時間 datetime,金額 int insert t select 2007 1 1 10 00 23 8 union all select 2007 1 1 01 00 04 4 union all select 2007 1 1 01 00 14 4 union...

判斷整除並求和

private sub command1 click dim m as integer,n as integer,d asinteger dim s as long 儲存結果 m val text1.text n val text2.text d val text3.text s 0 sum m,n...