如何合并数据表中的两列并使其成为单列 [英] How to merge two columns from a datatable and make it single column

查看:86
本文介绍了如何合并数据表中的两列并使其成为单列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据表中,我有4列日期,时间,值1和值2.

In my datatable I have 4 columns date, time, value1 and value2.

日期               时间          VALUE1          VALUE2

05/16/2019      15:08:02      2.01              1.01

05/16/2019      15:08:03      4.02              1.02

05/16/2019      15:08:04      5.03              1.03

Date                Time          VALUE1         VALUE2
05/16/2019     15:08:02     2.01             1.01
05/16/2019     15:08:03     4.02             1.02
05/16/2019     15:08:04     5.03             1.03

我想合并日期和时间列 在数据表中进入一个名为datetime的列,需要用逗号合并日期和时间值。

I want to merge date and time columns  in the datatable into a single column called datetime and need to merge date and time values with comma.

我想要如下。

DateTime                          VALUE1        VALUE2

05/16 / 2019,15:08:02        2.01              1.01

05/16 / 2019,15:08:03        4.02              1.02

05/16 / 2019,15:08:04        5.03              1.03

DateTime                         VALUE1       VALUE2
05/16/2019,15:08:02       2.01             1.01
05/16/2019,15:08:03       4.02             1.02
05/16/2019,15:08:04       5.03             1.03

如何实现?

请帮助我。

推荐答案

你有哪个数据库,SQL?

Which database do you have, SQL?

这个新列只是用于请求或者是将日期和时间更改为DateTime吗?

This new column is only for request or is to change Date and Time to DateTime definitely?

我认为最好保存已保存separeted(不是将日期时间保存为字符串)并在选择中将DateTime作为示例添加到单个列中作为示例

I think it is better keep saved separeted (to not save date time as string) and in the select you get DateTime into a single column as exemplo below

SELECT CONCAT(Date, CONCAT(',', Time)) DateTime, VALUE1, VALUE2 FROM ...





这篇关于如何合并数据表中的两列并使其成为单列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆