http://www.7gclub.com/table1.jpg
http://www.7gclub.com/table2.jpg
这个问题跟两个表有关第
首先,table1里的sort这个字段的数据都要查询出来
然后,table2里的quantity字段要根据sortid里行求和 然后再查询出来
请问这样的查询语句要怎么写呢 请那位朋友帮忙一下 谢谢了
小弟在线等哦
17 个解决方案
#1
取点数据贴出来撒...
#2
数据在那个两个图片里
#3
我这看不到图片,你写一段出来...
#4
好的 请等一下
#5
彩霞mm 我只差 100 分了
#6
sortid typeid typeid_2 Specifications Quantity
1 1 1 Size 1 10001
1 1 2 Size 2 10002
1 1 3 Size 3 10003
1 1 4 Size 4 10004
1 2 24 Size 5 10005
1 2 25 Size 6 10006
2 88 339 Size 7 10007
2 88 340 Size 8 10008
2 88 341 Size 9 10009
2 89 342 Size 10 10010
2 89 343 Size 11 10011
1 1 8 Size 12 10012
1 2 31 Size 13 10013
1 2 32 Size 14 10014
1 2 33 Size 15 10015
1 2 34 Size 16 10015
1 2 35 Size 17 10015
1 2 36 Size 18 10015
1 4 86 Size 19 10015
1 4 87 Size 20 10015
1 4 88 Size 21 10015
1 4 89 Size 22 10015
1 4 90 Size 23 10015
1 4 91 Size 24 10015
1 9 149 Size 25 10015
1 9 150 Size 26 10015
1 9 151 Size 27 10015
1 9 152 Size 28 10015
1 9 153 Size 29 10015
1 21 256 Size 30 10015
2 88 337 Size 31 10015
2 88 338 Size 32 10015
2 88 339 Size 33 10015
2 88 340 Size 34 10015
2 88 341 Size 35 10015
2 89 342 Size 36 10015
2 92 361 Size 37 10015
2 92 362 Size 38 10015
2 93 363 Size 39 10015
这是table2里的数据
SortID SN Sort
6 2 Agriculture
3 3 Apparel & Fashion
21 4 Automobile
35 5 Business Services
16 6 Chemicals
5 7 Computer Hardware & Software
15 8 Construction & Material
33 9 Electrical Equipment & Supplies
40 10 Electronic Components & Supplies
2 11 Energy
26 12 Environment
31 13 Excess Inventory
36 14 Fine Chemicals
20 15 Food & Beverage
41 16 Garment
12 17 Gifts & Crafts
37 18 Hardware & Tools
10 19 Health & Beauty
9 20 Home Appliances
4 21 Home Supplies
39 22 Lights & Lighting
1 23 Machinery & Industrial Supplies
这是table1里的数据
1 1 1 Size 1 10001
1 1 2 Size 2 10002
1 1 3 Size 3 10003
1 1 4 Size 4 10004
1 2 24 Size 5 10005
1 2 25 Size 6 10006
2 88 339 Size 7 10007
2 88 340 Size 8 10008
2 88 341 Size 9 10009
2 89 342 Size 10 10010
2 89 343 Size 11 10011
1 1 8 Size 12 10012
1 2 31 Size 13 10013
1 2 32 Size 14 10014
1 2 33 Size 15 10015
1 2 34 Size 16 10015
1 2 35 Size 17 10015
1 2 36 Size 18 10015
1 4 86 Size 19 10015
1 4 87 Size 20 10015
1 4 88 Size 21 10015
1 4 89 Size 22 10015
1 4 90 Size 23 10015
1 4 91 Size 24 10015
1 9 149 Size 25 10015
1 9 150 Size 26 10015
1 9 151 Size 27 10015
1 9 152 Size 28 10015
1 9 153 Size 29 10015
1 21 256 Size 30 10015
2 88 337 Size 31 10015
2 88 338 Size 32 10015
2 88 339 Size 33 10015
2 88 340 Size 34 10015
2 88 341 Size 35 10015
2 89 342 Size 36 10015
2 92 361 Size 37 10015
2 92 362 Size 38 10015
2 93 363 Size 39 10015
这是table2里的数据
SortID SN Sort
6 2 Agriculture
3 3 Apparel & Fashion
21 4 Automobile
35 5 Business Services
16 6 Chemicals
5 7 Computer Hardware & Software
15 8 Construction & Material
33 9 Electrical Equipment & Supplies
40 10 Electronic Components & Supplies
2 11 Energy
26 12 Environment
31 13 Excess Inventory
36 14 Fine Chemicals
20 15 Food & Beverage
41 16 Garment
12 17 Gifts & Crafts
37 18 Hardware & Tools
10 19 Health & Beauty
9 20 Home Appliances
4 21 Home Supplies
39 22 Lights & Lighting
1 23 Machinery & Industrial Supplies
这是table1里的数据
#7
请问这个语句要怎么写啊?
#8
select a.sortID ,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
#9
根据 table1 求 table2 的 quantity 吗?
#10
- -#那偶不抢了记得散分时给我多留点,HOHO~
#11
对的
要的显示效果是:
Agriculture 253456234
Apparel & Fashion 253456234
Automobile 253456234
Business Services 253456234
Chemicals 0
Computer Hardware & Software
Construction & Material
Electrical Equipment & Supplies
Electronic Components & Supplies
Energy
Environment
Excess Inventory
Fine Chemicals
Food & Beverage
Garment
Gifts & Crafts
Hardware & Tools
Health & Beauty
Home Appliances
Home Supplies
Lights & Lighting
Machinery & Industrial Supplies
就是说table1里的sort全要显示出来
而table2里的quantity不一定有数据(就像现在的table2表里,sortid只有1和2),所以求的和也只有sortid为1和2的时候的和
我可能说得不是很清楚 请见谅
要的显示效果是:
Agriculture 253456234
Apparel & Fashion 253456234
Automobile 253456234
Business Services 253456234
Chemicals 0
Computer Hardware & Software
Construction & Material
Electrical Equipment & Supplies
Electronic Components & Supplies
Energy
Environment
Excess Inventory
Fine Chemicals
Food & Beverage
Garment
Gifts & Crafts
Hardware & Tools
Health & Beauty
Home Appliances
Home Supplies
Lights & Lighting
Machinery & Industrial Supplies
就是说table1里的sort全要显示出来
而table2里的quantity不一定有数据(就像现在的table2表里,sortid只有1和2),所以求的和也只有sortid为1和2的时候的和
我可能说得不是很清楚 请见谅
#12
楼上的两位朋友 再来看看啊
#13
------------那改改...
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
你看看...
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
你看看...
#14
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
这个要怎么操作啊?
#15
服务器: 消息 409,级别 16,状态 2,行 1
sum or average aggregate 运算不能以 nvarchar 数据类型作为参数。
sum or average aggregate 运算不能以 nvarchar 数据类型作为参数。
#16
终于可以了 太谢谢两位了!
#17
clbo() ( ) 信誉:100 Blog 2006-12-15 16:04:22 得分: 0
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
------------------
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(cast(quantity as decimal(9,4))) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
--再看看...
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
------------------
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(cast(quantity as decimal(9,4))) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
--再看看...
#1
取点数据贴出来撒...
#2
数据在那个两个图片里
#3
我这看不到图片,你写一段出来...
#4
好的 请等一下
#5
彩霞mm 我只差 100 分了
#6
sortid typeid typeid_2 Specifications Quantity
1 1 1 Size 1 10001
1 1 2 Size 2 10002
1 1 3 Size 3 10003
1 1 4 Size 4 10004
1 2 24 Size 5 10005
1 2 25 Size 6 10006
2 88 339 Size 7 10007
2 88 340 Size 8 10008
2 88 341 Size 9 10009
2 89 342 Size 10 10010
2 89 343 Size 11 10011
1 1 8 Size 12 10012
1 2 31 Size 13 10013
1 2 32 Size 14 10014
1 2 33 Size 15 10015
1 2 34 Size 16 10015
1 2 35 Size 17 10015
1 2 36 Size 18 10015
1 4 86 Size 19 10015
1 4 87 Size 20 10015
1 4 88 Size 21 10015
1 4 89 Size 22 10015
1 4 90 Size 23 10015
1 4 91 Size 24 10015
1 9 149 Size 25 10015
1 9 150 Size 26 10015
1 9 151 Size 27 10015
1 9 152 Size 28 10015
1 9 153 Size 29 10015
1 21 256 Size 30 10015
2 88 337 Size 31 10015
2 88 338 Size 32 10015
2 88 339 Size 33 10015
2 88 340 Size 34 10015
2 88 341 Size 35 10015
2 89 342 Size 36 10015
2 92 361 Size 37 10015
2 92 362 Size 38 10015
2 93 363 Size 39 10015
这是table2里的数据
SortID SN Sort
6 2 Agriculture
3 3 Apparel & Fashion
21 4 Automobile
35 5 Business Services
16 6 Chemicals
5 7 Computer Hardware & Software
15 8 Construction & Material
33 9 Electrical Equipment & Supplies
40 10 Electronic Components & Supplies
2 11 Energy
26 12 Environment
31 13 Excess Inventory
36 14 Fine Chemicals
20 15 Food & Beverage
41 16 Garment
12 17 Gifts & Crafts
37 18 Hardware & Tools
10 19 Health & Beauty
9 20 Home Appliances
4 21 Home Supplies
39 22 Lights & Lighting
1 23 Machinery & Industrial Supplies
这是table1里的数据
1 1 1 Size 1 10001
1 1 2 Size 2 10002
1 1 3 Size 3 10003
1 1 4 Size 4 10004
1 2 24 Size 5 10005
1 2 25 Size 6 10006
2 88 339 Size 7 10007
2 88 340 Size 8 10008
2 88 341 Size 9 10009
2 89 342 Size 10 10010
2 89 343 Size 11 10011
1 1 8 Size 12 10012
1 2 31 Size 13 10013
1 2 32 Size 14 10014
1 2 33 Size 15 10015
1 2 34 Size 16 10015
1 2 35 Size 17 10015
1 2 36 Size 18 10015
1 4 86 Size 19 10015
1 4 87 Size 20 10015
1 4 88 Size 21 10015
1 4 89 Size 22 10015
1 4 90 Size 23 10015
1 4 91 Size 24 10015
1 9 149 Size 25 10015
1 9 150 Size 26 10015
1 9 151 Size 27 10015
1 9 152 Size 28 10015
1 9 153 Size 29 10015
1 21 256 Size 30 10015
2 88 337 Size 31 10015
2 88 338 Size 32 10015
2 88 339 Size 33 10015
2 88 340 Size 34 10015
2 88 341 Size 35 10015
2 89 342 Size 36 10015
2 92 361 Size 37 10015
2 92 362 Size 38 10015
2 93 363 Size 39 10015
这是table2里的数据
SortID SN Sort
6 2 Agriculture
3 3 Apparel & Fashion
21 4 Automobile
35 5 Business Services
16 6 Chemicals
5 7 Computer Hardware & Software
15 8 Construction & Material
33 9 Electrical Equipment & Supplies
40 10 Electronic Components & Supplies
2 11 Energy
26 12 Environment
31 13 Excess Inventory
36 14 Fine Chemicals
20 15 Food & Beverage
41 16 Garment
12 17 Gifts & Crafts
37 18 Hardware & Tools
10 19 Health & Beauty
9 20 Home Appliances
4 21 Home Supplies
39 22 Lights & Lighting
1 23 Machinery & Industrial Supplies
这是table1里的数据
#7
请问这个语句要怎么写啊?
#8
select a.sortID ,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
#9
根据 table1 求 table2 的 quantity 吗?
#10
- -#那偶不抢了记得散分时给我多留点,HOHO~
#11
对的
要的显示效果是:
Agriculture 253456234
Apparel & Fashion 253456234
Automobile 253456234
Business Services 253456234
Chemicals 0
Computer Hardware & Software
Construction & Material
Electrical Equipment & Supplies
Electronic Components & Supplies
Energy
Environment
Excess Inventory
Fine Chemicals
Food & Beverage
Garment
Gifts & Crafts
Hardware & Tools
Health & Beauty
Home Appliances
Home Supplies
Lights & Lighting
Machinery & Industrial Supplies
就是说table1里的sort全要显示出来
而table2里的quantity不一定有数据(就像现在的table2表里,sortid只有1和2),所以求的和也只有sortid为1和2的时候的和
我可能说得不是很清楚 请见谅
要的显示效果是:
Agriculture 253456234
Apparel & Fashion 253456234
Automobile 253456234
Business Services 253456234
Chemicals 0
Computer Hardware & Software
Construction & Material
Electrical Equipment & Supplies
Electronic Components & Supplies
Energy
Environment
Excess Inventory
Fine Chemicals
Food & Beverage
Garment
Gifts & Crafts
Hardware & Tools
Health & Beauty
Home Appliances
Home Supplies
Lights & Lighting
Machinery & Industrial Supplies
就是说table1里的sort全要显示出来
而table2里的quantity不一定有数据(就像现在的table2表里,sortid只有1和2),所以求的和也只有sortid为1和2的时候的和
我可能说得不是很清楚 请见谅
#12
楼上的两位朋友 再来看看啊
#13
------------那改改...
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
你看看...
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(quantity) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
你看看...
#14
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
这个要怎么操作啊?
#15
服务器: 消息 409,级别 16,状态 2,行 1
sum or average aggregate 运算不能以 nvarchar 数据类型作为参数。
sum or average aggregate 运算不能以 nvarchar 数据类型作为参数。
#16
终于可以了 太谢谢两位了!
#17
clbo() ( ) 信誉:100 Blog 2006-12-15 16:04:22 得分: 0
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
------------------
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(cast(quantity as decimal(9,4))) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
--再看看...
这里还有个问题 quantity这个字段是nvachar类型不能进行sum求和运算
这个要怎么操作啊?
------------------
select a.Sort,isnull (b.sm ,0) as quantity
from table1 a
left join
(
select sortid ,sum(cast(quantity as decimal(9,4))) as sm
from table2
group by sortid
) b on a.sortID =b.sortID
order by a.Sort
--再看看...