运行sql查询将内容导出为CSV文件我注意到某些列没有正确显示。在我的投射日期时间戳没有在单元格中正确显示
代码如下:
COPY (select hostname as "Host Name",devicetype as "Device Type",platform as "Model",Ipaddress as "IP Address",swversion as "Software Version",configuredTime as "Configured",activeTime as "Active",cluster as "Clusters",location as "Location",macaddress as "Mac Address",devicepool as "Device Pool" from (select getmodelinfo.ipaddress,max(getmodelinfo.hostname) as
hostname, max(getmodelinfo.macaddress) as macaddress,
max(getmodelinfo.devicetype) as devicetype,
max(getmodelinfo.platform) as platform,
max(getmodelinfo.swversion) as swversion, min(getmodelinfo.day_end_date) as configuredtime,
max(getmodelinfo.active_end_date) as activetime,
max(getmodelinfo.ucmclustername)
as cluster, max(getmodelinfo.ucmlocation) as location,
max(getmodelinfo.ucmdevicepool) as devicepool from (select
pcwh_inv.uniquedeviceid,pcwh_inv.ipaddress,
pcwh_inv.endpointmodel, pcwh_inv.hostname, pcwh_inv.devicetype, pcwh_inv.platform,
pcwh_inv.macaddress, pcwh_inv.version as
swversion,pcwh_inv.deployed_day_end_date as day_end_date,
pcwh_inv.lastupdated_day_end_date as active_end_date,
pcwh_inv.ucmclustername,pcwh_inv.ucmlocation,pcwh_inv.ucmdevicepool
from pcwh_inventory_20160410 pcwh_inv,
(select pcwh_inv.uniquedeviceid, max(pcwh_inv.lastupdated_day_end_date) as
lasttime from pcwh_inventory_20160410 pcwh_inv where pcwh_inv.ipaddress
notnull group by
pcwh_inv.uniquedeviceid)gettime where pcwh_inv.endpointmodel = 'SX' and
pcwh_inv.uniquedeviceid = gettime.uniquedeviceid and
pcwh_inv.lastupdated_day_end_date = gettime.lasttime and pcwh_inv.mgmtstatus not in ('Deleted')
)getmodelinfo group by ipaddress) M) TO '/opt/emms/emsam/export/raj2.csv' DELIMITER ',' CSV HEADER
请在下面找到我在运行查询时得到的结果的屏幕截图,不导出到csv,导出到csv(下图),单击特定行内容时单元格内容的图像虽然正确显示(最底层图像)
在我看来,格式化csv文件的问题,请你告诉我如何从查询级别执行此操作以显示db列中的确切内容?
答案 0 :(得分:2)
我相信您的代码没有任何问题,但是Excel将该列视为日期之外的其他内容,这种情况经常发生。可以通过选择所有受影响的单元格,右键单击以及通过后续菜单将格式更改为文本来解决此问题。
如果这个CSV将被另一个应用程序进一步操纵,我认为你不会有问题,因为数据看起来很好。
如果由于某种原因您需要动态地在Excel中正确显示它,您可能需要查看类似的内容。Java - Excel Cell Type
答案 1 :(得分:1)
问题很简单,CSV格式没有错误。实际上,您所做的数据输入方式错误,因此数据条目中没有空格会导致问题。 因此,在第6和第7列中,您可以看到数据条目之间存在空间,因此正在发生问题。 为了防止这种情况,只需为日期添加新列。 它将解决所有问题,数据将输入您的数据库。