2016-04-28 19 views
0

我正在使用MySql工作台备份来自Magento数据库的数据。下面是我使用的查询:需要从MySql结果中修剪新行

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') 

我真正需要做的是剥离新的线条勾勒出地址1场的,因为它打破了我使用CSV解析器。我试过了:

TRIM(\n FROM Address1.value) as Address1 

对查询的第四行,但那是不成功的。我对MySql的知识显然是有限的,任何帮助都会为我节省几个小时来删除新行。

回答

0

用不同的路线前进。

摆脱装饰和东西

TRIM(\n FROM Address1.value) as Address1 

将被

table.address1 as Address1 

然后所有的联接添加一个WHERE子句,并设置到其中,你会考虑新的日期之后。

会是这样的:

WHERE date =< 2016-04-28 

这应该让这个它只会显示与日期列比今天的日期的行。

哦,还有,如果你实际上不想使用日期列,但你知道什么ID号的新行开始,你总是可以使用它。它应该是相同的语法,但具有不同的列

希望有所帮助。如果你需要更多的帮助,请让我知道

另一件需要注意的是它建议有小写的表和列名。所以我会做这些一些编辑,以及与确保一切是因为SQL承认资本

+0

我需要所有的人,所以我不希望按日期有限制WHERE子句。我需要的是确保Address1.value中没有任何换行符(\ n)的方法。 – natep

+0

如何尝试:其中address1.value NOT LIKE'/ n' 应该收集子字符串/ n并且不允许它。更多的是你在找什么? –

1

你可以从Address1.value场运行

UPDATE customer_address_entity_text SET value=REPLACE(value,'\n','') 

,并删除所有“\ n”小写之后运行您的查询。

另一个解决方案是在你的SELECT语句中使用REPLACE()

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')