创建视图的显示方式与选择不同

时间:2017-12-15 22:59:18

标签: mysql

我正在尝试创建一个视图,而select语句正是我想要看到的,但是当我使用与create view语句完全相同的select语句时,它会以不同方式解析信息。这是select语句。

CREATE VIEW shippingview
AS
(   SELECT shipcarton.id AS shipcartonid
            ,ship.num AS shipnum
            ,so.num AS sonum
            ,so.customerpo AS customerpo
            ,so.email AS email
            ,so.phone AS phone
            ,countryconst.abbreviation AS country
            ,stateconst.code AS STATE
            ,ship.shiptozip AS postalcode
            ,ship.shiptocity AS city
            ,carrierservice.name AS servicename
            ,carrierservice.code AS servicecode
            ,shipcarton.freightweight AS weight
            ,shipcarton.len AS length
            ,shipcarton.height AS height
            ,shipcarton.width AS width
            ,`ship`.`id` AS `shipID`
            ,(
                CASE 
                    WHEN (locate('\n', `ship`.`shipToAddress`) > 0)
                        THEN substr(`ship`.`shipToAddress`, 1, (locate('\n', `ship`.`shipToAddress`) - 1))
                    ELSE `ship`.`shipToAddress`
                    END
                ) AS `SHIPTOADDRESS1`
            ,(
                CASE 
                    WHEN (
                            (locate('\n', `ship`.`shipToAddress`) > 0)
                            AND (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) = 0)
                            )
                        THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1))
                    WHEN (
                            (locate('\n', `ship`.`shipToAddress`) > 0)
                            AND (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) > 0)
                            )
                        THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1), (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) - (locate('\n', `ship`.`shipToAddress`) + 1)))
                    ELSE ''
                    END
                ) AS `SHIPTOADDRESS2`
            ,(
                CASE 
                    WHEN (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) > 0)
                        THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) + 1))
                    ELSE ''
                    END
                ) AS `SHIPTOADDRESS3`
        FROM ship
        LEFT JOIN so ON ship.soid = so.id
        LEFT JOIN carrierservice ON ship.carrierserviceid = carrierservice.id
        LEFT JOIN countryconst ON ship.shiptocountryid = countryconst.id
        LEFT JOIN stateconst ON ship.shiptostateid = stateconst.id
        LEFT JOIN shipcarton ON shipcarton.shipid = ship.id
        WHERE ship.statusid IN (
                10
                ,20
                )
        )

它应该显示由换行符分隔的地址,它完全正确地作为选择而不是创建。

0 个答案:

没有答案