海友我在Sql Server中有一个问题我有一个表名表1喜欢 [英] Hai Friends I Have A Question In Sql Server I Had A Table Name Table1 Like

查看:79
本文介绍了海友我在Sql Server中有一个问题我有一个表名表1喜欢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

id name buyitems  cost
1  anil x;y;z     10;20;30
2  suni a;b;c     40;50;60



i想要这样的输出


i wanna output like this

id name   cost1  item1    cost2   item2   cost3 item3
1  anil    10      x       20       y       30     z



plz告诉我sql查询thankssss


plz tell me sql query thankssss

推荐答案

不,我不会。

我不会这么简单的原因:对于数据库表来说,这是一个非常非常糟糕的设计,如果你继续这样做,将来会给你带来很大的问题。

虽然可以做你想做的事,但它很笨拙,后来其他操作也很多,更复杂。



相反,改变你的数据库设计:添加一个或两个其他表:

No, I won't.
The reason I won't is simple: it's a very, very bad design for a database table, and it will give you huge problems in the future if you carry on that way.
While it is possible to do what you want, it's clumsy, and it makes other operations later a lot, lot more complicated.

Instead, change your DB design: add one or two other tables:
PurchasedItems Table:
id
custID  (foreign key to id from Table1)
itemId  (foreign key to id from Items table)
cost    value of transaction as a numeric field




Items Table:
id
itemName       (your x, or y, or a, or b)
description    (free text description of the item)



现在,当你想要获取单个项目时,它非常简单 - 你可以更简单地对数值进行数学计算同样。


Now when you want to fetch individual items it's pretty simple - and you can do math on the values a lot more simply as well.


这篇关于海友我在Sql Server中有一个问题我有一个表名表1喜欢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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