postgresql:将多列拆分为行

时间:2019-10-15 19:03:19

标签: sql postgresql

希望大家一切都好。

这是我的数据集的屏幕截图![enter image description here] 1

现在,实际的数据集目前有近三千行,而我正在努力做到的是将联系人从十二列分解为三列。

pollTimeout

有关如何处理此问题的任何建议? 谢谢大家!

2 个答案:

答案 0 :(得分:2)

使用python manage.py sql myproject

1. In Explorer, view the folder that the error says egg cache directory is set to
2. Delete (or rename) the file mysql_python-1.2.5-py2.7-win32.egg-tmp
3. That's it. The command now works and creates a new file in there. (Haven't tested if I need to do this every time.)

答案 1 :(得分:1)

使用横向连接:

select t.company_name, v.*
from t cross join lateral
     (values (t.contact, t.contact_position, t.email),
             (t.contact_2, t.contact_2_position, t.contact_2_email),
             (t.contact_3, t.contact_3_position, t.contact_3_email),
             . . .
     ) v(contact, contact_position, email);

您可能要添加:

where v.contact is not null

但这从您的样本数据中并不明显。

相关问题