mysql分時查詢並求和

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

1. 分時查詢

a. 分時查詢掛鍍線 條 產量

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 

b. 分時查詢滾鍍線 Kg產量

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 

c. 分時查詢貼片線 kg 產量

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 

 

2. 按時間查詢

a. 查詢時間段內滾鍍線kg產量

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 

b. 查詢時間段內掛鍍線條產量

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 

c. 查詢時間段內貼片線kg產量

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 

 

3. 查詢某個員工工作記錄

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

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

4. 查詢某個工位產量

a. 查詢除膠工位1的產量,除膠工位比較特殊,一個電腦三個工位

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

b. 查詢掛鍍上料製程操作記錄

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章