在mysql中包含别名字段到另一个别名

时间:2016-04-29 02:40:19

标签: mysql sql alias

我有一个表以小时 - 分钟浮动格式存储值,并且我从数据库中提取数据,同时使用此查询将小时分钟浮动转换为分钟。

SELECT 
    DailyTimelog.id,
    DailyTimelog.payroll_cut_off_id,
    DailyTimelog.employee_id,
    DailyTimelog.work_shift_id,
    DailyTimelog.employee_status,
    DailyTimelog.timelog_date,
    DailyTimelog.is_rest_day,
    DailyTimelog.is_on_leave,
    DailyTimelog.is_holiday,
    DailyTimelog.is_regular_holiday,
    DailyTimelog.is_special_holiday,
    DailyTimelog.is_absent,
    (
        (SUBSTRING_INDEX(tardiness_hours, '.', 1)*60)
        +(
            case when (INSTR(tardiness_hours, '.') = 0) 
                THEN 0 
                ELSE SUBSTRING_INDEX(tardiness_hours, '.', -1) 
            END)
    ) as tardiness_hours,
    (
        (SUBSTRING_INDEX(leave_hours, '.', 1)*60)
        +(
            case when (INSTR(leave_hours, '.') = 0) 
                THEN 0 
                ELSE SUBSTRING_INDEX(leave_hours, '.', -1) 
            END)
    ) as leave_hours,
    DailyTimelog.leave_credit_used,
    (
        (SUBSTRING_INDEX(normal_work_hrs, '.', 1)*60)
        +(
            case when (INSTR(normal_work_hrs, '.') = 0) 
                THEN 0 
                ELSE SUBSTRING_INDEX(normal_work_hrs, '.', -1) 
            END)
    ) as normal_work_hrs,
    (
        (SUBSTRING_INDEX(overtime_work_hrs, '.', 1)*60)
        +(
            case when (INSTR(overtime_work_hrs, '.') = 0) 
                THEN 0 
                ELSE SUBSTRING_INDEX(overtime_work_hrs, '.', -1) 
            END)
    ) as overtime_work_hrs,
    (
        (SUBSTRING_INDEX(night_premium_work_hrs, '.', 1)*60)
        +(
            case when (INSTR(night_premium_work_hrs, '.') = 0) 
                THEN 0 
                ELSE SUBSTRING_INDEX(night_premium_work_hrs, '.', -1) 
            END)
    ) as night_premium_work_hrs

    FROM `daily_timelogs` as DailyTimelog WHERE DailyTimelog.payroll_cut_off_id = 404

当我使用print_f()输出数据时,我得到这样的结果:

 [DailyTimelog] => Array
            (
                [id] => 93608
                [payroll_cut_off_id] => 404
                [employee_id] => 126
                [work_shift_id] => 11
                [employee_status] => 2
                [timelog_date] => 2016-03-27
                [is_rest_day] => 1
                [is_on_leave] => 
                [is_holiday] => 
                [is_regular_holiday] => 
                [is_special_holiday] => 
                [is_absent] => 
                [leave_credit_used] => 0
            )

        [0] => Array
            (
                [tardiness_hours] => 0
                [leave_hours] => 0
                [normal_work_hrs] => 0
                [overtime_work_hrs] => 0
                [night_premium_work_hrs] => 0
            )

有没有办法将索引0包含在DailyTimelogs索引中,同时还在mysql上?

0 个答案:

没有答案