如何在sql中使用数据 [英] How to use the data in sql

查看:90
本文介绍了如何在sql中使用数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我有这样的桌子



ID       ; NAME1                age

1       aaa,bbb,ccc          20,30 ,40



如果我使用'aaa'查询意味着我想要20,bbb意味着30,ccc意味着40




任何建议请...........

Hi
I have the table like this

ID       name1               age
1      aaa,bbb,ccc         20,30,40

if i query using 'aaa' mean i want to get 20,bbb mean 30 ,ccc means 40


Any suggestions pls...........

推荐答案

这是一个糟糕的数据库设计:你可以做到 - 它一点也不简单,但你可以做到 - 但它只是不能很好地利用资源。

相反,将你的Name1和age列分成不同的列,给它们正确的数据类型,所以你的数值存储在数字字段中,并这样做:



That is a poor database design: you can do it - it's not at all simple, but you can do it - but it's just not a good use of resources.
Instead, separate your Name1 and age columns into separate columns, given them proper datatypes, so your numeric values are stored in numeric fields, and do it that way:

ID Name1 Age
1  aaa   20
1  bbb   30
1  ccc   40

从长远来看,这会让你的生活变得更加简单!



和顺便说一句:您可能不希望将年龄存储为数字:根据所需日期,它是一个移动值。相反,你最好使用DateTime列,然后存储Birthdate - 这样可以很容易地计算出Age并且总是正确的......

It will make your life a lot, lot simpler in the long run!

And BTW: you probably don't want to store "Age" as a number: it's a moving value depending on the required date. Instead, you would be better using a DateTime column, and storing the Birthdate instead - that way the Age can be easily worked out and is always correct...


这篇关于如何在sql中使用数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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