MySQL表视图数据类型

时间:2019-04-21 17:22:09

标签: mysql

我正在尝试将数据类型bigint(37)更改为int(11)。我尝试了几种方法CAST或CONVERT,但未成功结束。

如何在此表VIEW中更改数据类型?请。谢谢。

enter image description here

CREATE OR REPLACE VIEW gtemp_view AS
    SELECT
    d1.Week AS Week1,
    d2.Week AS Week2,
    IF( ABS(d1.dt1-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt4)=0,1,0) AS mcount
FROM gtemp AS d1 , gtemp AS d2 WHERE d1.Week IS NOT NULL AND d2.Week IS NOT NULL AND d1.Week > d2.Week order by Week1 DESC, Week2 DESC limit 200000;

1 个答案:

答案 0 :(得分:2)

如果您不希望在视图架构中看到INT37,则可以尝试使用显式强制类型转换为无符号

CREATE OR REPLACE VIEW gtemp_view AS
    SELECT
    d1.Week AS Week1,
    d2.Week AS Week2,
    cast( 
    (IF( ABS(d1.dt1-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt1-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt2-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt3-d2.dt4)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt1)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt2)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt3)=0,1,0) +
    IF( ABS(d1.dt4-d2.dt4)=0,1,0)) 
    AS UNIGNED) mcount
FROM gtemp AS d1 , gtemp AS d2 
WHERE d1.Week IS NOT NULL 
AND d2.Week IS NOT NULL 
AND d1.Week > d2.Week 
order by Week1 DESC, Week2 DESC limit 200000;

无论如何,强制类型转换应该以几种方式影响性能。.相反,INT37数据类型不应导致明显的性能下降