我正在使用MySql工作台备份Magento数据库中的数据。这是我正在使用的查询:
Select FName.value AS 'FirstName' ,
LName.value AS 'LastName' ,
e.email,
Address1.value AS Address1,
City.value AS City ,
Province.value as Province ,
Country.value AS 'CountryCode' ,
Zip.value AS Zip ,
Phone.value AS Phone
FROM customer_entity e
JOIN customer_address_entity ae ON ae.parent_id = e.entity_id
JOIN customer_entity_int cei ON e.entity_id = cei.entity_id and cei.attribute_id=13 and cei.value=ae.entity_id
left JOIN customer_address_entity_varchar FName ON ae.entity_id = FName.entity_id and FName.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='firstname')
left JOIN customer_address_entity_varchar LName ON ae.entity_id = LName.entity_id and LName.attribute_id= (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='lastname')
left JOIN customer_address_entity_varchar Zip ON ae.entity_id = Zip.entity_id and Zip.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='postcode')
left JOIN customer_address_entity_varchar City ON ae.entity_id = City.entity_id and City.attribute_id= (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='city')
left JOIN customer_address_entity_varchar Phone ON ae.entity_id = Phone.entity_id and Phone.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='telephone')
left JOIN customer_address_entity_varchar Province ON ae.entity_id = Province.entity_id and Province.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='region')
left JOIN customer_address_entity_varchar Country ON ae.entity_id = Country.entity_id and Country.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='country_id')
left JOIN customer_address_entity_text Address1 ON ae.entity_id = Address1.entity_id and Address1.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='street')
我真正需要做的就是从Address1字段中删除新行,因为它打破了我使用的CSV解析器。我试过了:
TRIM(\n FROM Address1.value) as Address1
在查询的第四行,但这是不成功的。我对MySql的了解显然是有限的,任何帮助都会节省我几个小时删除新行。
答案 0 :(得分:1)
你可以删除所有" \ n"从Address1.value
字段运行
UPDATE customer_address_entity_text SET value=REPLACE(value,'\n','')
然后运行您的查询。
另一种解决方案是在REPLACE()
声明中使用SELECT
:
REPLACE(Address1.value, '\n', '') as Address1
导致
Select FName.value AS 'FirstName' ,
LName.value AS 'LastName' ,
e.email,
REPLACE(Address1.value, '\n', '') AS Address1,
City.value AS City ,
Province.value as Province ,
Country.value AS 'CountryCode' ,
Zip.value AS Zip ,
Phone.value AS Phone
FROM customer_entity e
JOIN customer_address_entity ae ON ae.parent_id = e.entity_id
JOIN customer_entity_int cei ON e.entity_id = cei.entity_id and cei.attribute_id=13 and cei.value=ae.entity_id
left JOIN customer_address_entity_varchar FName ON ae.entity_id = FName.entity_id and FName.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='firstname')
left JOIN customer_address_entity_varchar LName ON ae.entity_id = LName.entity_id and LName.attribute_id= (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='lastname')
left JOIN customer_address_entity_varchar Zip ON ae.entity_id = Zip.entity_id and Zip.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='postcode')
left JOIN customer_address_entity_varchar City ON ae.entity_id = City.entity_id and City.attribute_id= (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='city')
left JOIN customer_address_entity_varchar Phone ON ae.entity_id = Phone.entity_id and Phone.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='telephone')
left JOIN customer_address_entity_varchar Province ON ae.entity_id = Province.entity_id and Province.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='region')
left JOIN customer_address_entity_varchar Country ON ae.entity_id = Country.entity_id and Country.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='country_id')
left JOIN customer_address_entity_text Address1 ON ae.entity_id = Address1.entity_id and Address1.attribute_id = (select attribute_id from eav_attribute where entity_type_id=2 and attribute_code='street')
答案 1 :(得分:0)
以不同的路线前进。
摆脱修剪和东西
TRIM(\n FROM Address1.value) as Address1
将是
table.address1 as Address1
然后在所有连接之后添加一个WHERE子句并将其设置为您认为是新的日期。
会是这样的:
WHERE date =< 2016-04-28
这应该使它只显示日期列比今天更早的行。
哦,如果你真的不想使用日期专栏,但是你知道新行开始的ID#,你也可以随时使用它。它应该是相同的语法,但具有不同的列
希望有所帮助。如果您需要更多帮助,请知道
另外需要注意的是,建议将表和列名称设置为小写。所以我也会对这些进行一些编辑,并确保一切都是小写的,因为SQL识别出大写