对于垂直设计的表如何排序:例如:
表: Product
表:AttributeID NAME VALUE ProductID
01 Attribute1 value1 1
02 Attribute2 value2 1
03 Attribute3 value3 2
04 Attribute4 value4 2
05 Attribute5 value5 2
....
每个product 都有50~150个Attribute(数目不一定)如果我想对结果进行product attribute1 的值得排序,如何排序阿
表: Product
表:AttributeID NAME VALUE ProductID
01 Attribute1 value1 1
02 Attribute2 value2 1
03 Attribute3 value3 2
04 Attribute4 value4 2
05 Attribute5 value5 2
....
每个product 都有50~150个Attribute(数目不一定)如果我想对结果进行product attribute1 的值得排序,如何排序阿
因为product 表可以连接到attribute 表获得所有相应信息然后我要对这些product 进行排序,依据attribute1 从大到小排序
P.product ,A.NAME
FROM product P,attribute A WHERE P.productID=A.productID
ORDER BY P.product ,A.NAME DESC
a.product,b.name
from
product a
join
attribute b
on
a.productID=b.productID
order by
a.product,b.name desc
表Product
ID Name
1 BAG
2 BOOK表Attribute
ID NAME VALUE ProductID
01 Attribute1 111 1
02 Attribute2 2222 1
03 Attribute1 11 2
04 Attribute2 222 2
05 Attribute5 33333 2 求:
对Product
依据attribute1 的值从大到小排序因为对于Product 1 的 attribute 1=111
Product 2 的 attribute 1=11所以Product 1 要排在Product 2前面
a.product,b.name
from
product a
join
attribute b
on
a.productID=b.productID
order by
a.product,b.name
A.NAME,A.[VALUE]
FROM product P,attribute A WHERE P.productID=A.productID
ORDER BY A.NAME ,A.[VALUE] DESC
Value类型也很多,要求是能按:Attribute1, attribute2, attribute3 值排序
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。