2012-08-16 45 views
2

當我運行附加的例子,它創建表的列ID和數據類型bigint(295) 我想定義它爲int(11)。 在更復雜的查詢中(我從組concat中獲得了ID)我得到了文本而不是int。如何在創建表上指定數據類型爲select in mysql?

如何在創建表上指定數據類型爲select in mysql?

DROP TABLE IF EXISTS some_table; 
CREATE TABLE IF NOT EXISTS some_table AS (
SELECT 
CONVERT("123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369 
    ,2123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369 
    ,3123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369" 
, SIGNED INTEGER) AS id); 

回答

1

我找不到直接的方法來做到這一點。 解決它通過改變表,工作我,也許有更好的解決方案。

DROP TABLE IF EXISTS some_table; 
CREATE TABLE IF NOT EXISTS some_table AS (
SELECT 
CONVERT("123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369 
    ,2123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369 
    ,3123,456,789,987,654,321,741,852,963,147,258,369,123,456,789,987,654,321,741,852,963,147,258,369" 
, SIGNED INTEGER) AS id); 

ALTER TABLE some_table CHANGE id id INT(11) NULL DEFAULT NULL ; 
相關問題