我正在加入2张桌子,我正在做
select distinct Package_id, package_title, durationindays,videourl,package_image_1,package_image_2,package_image_3,package_image_4,
package_image_5, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
结果就像这样
ID | Package_title | DurationInDays | VideoUrl | Package_Image_1 | Package_Image_2 |Package_Image_3 | Package_Image_4 | Package_Image_5
001 | Title | 5 | www.youtube.com?1231 | www.images.com/image1 | www.images.com/image2 | wwww.images.com/image3 | www.images.com/image4 | image5
注意:所有图片都有不同的列
我想为所有5张图片只创建一列,所以结果应该是这样的
ID |Package_title|DurationInDays | VideoUrl | Package_Images |
001 |Title |5 | www.youtube.com?123| www.images.com/image1 |
| | | | www.images.com/image2 |
| | | | www.images.com/image3 |
| | | | www.images.com/image4 |
| | | | image5 |
请帮我解决这个问题。 谢谢
答案 0 :(得分:0)
select distinct Package_id, package_title, durationindays,videourl,package_image_1 + ',' + package_image_2 + ',' + package_image_3 + ',' + package_image_4 + ',' + package_image_5 As Pacakage, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
您可以使用任何分隔符而不是逗号。
答案 1 :(得分:0)
您可以使用“UNION ALL”来完成此任务。
select distinct Package_id, package_title, durationindays,videourl,package_image_1 as package_image, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
UNION ALL
select distinct Package_id, package_title, durationindays,videourl,package_image_2 as package_image, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
UNION ALL
select distinct Package_id, package_title, durationindays,videourl,package_image_3 as package_image, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
UNION ALL
select distinct Package_id, package_title, durationindays,videourl,package_image_4 as package_image, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'
UNION ALL
select distinct Package_id, package_title, durationindays,videourl,package_image_5 as package_image, Rating, AdultPrice
from packages
inner join
rates_and_dates on rates_and_dates.package = packages.package_id
where package_id=1 and adultprice='4500'