对象资源表:
ObjectID|Resource
01 | Resource A
01 | Resource B
对象可用性表:
AvailID|DayName
01 | Monday
02 | Tuesday
ObjectResourceAvailability表:
ObjectID|Resource Name|Day
01 |ResourceA | 01
理想情况下应该显示
ObjectID|Resource Name|DayName
01 |ResourceA, ResourceB | Monday, Tuesday
我还连接了具有相同ID的列。 如何才能使最终结果显示在周一而不是01?我已经尝试选择ObjAvail.DayName并更改连接字符串解决方案,但我一直在选择列表中使列无效,因为它不包含在聚合函数或GROUP BY子句中。
这是帮助我实现连接列的解决方案
SELECT
t1.oid
,STUFF(
(SELECT
', ' + t2.resource
FROM objectresource t2
WHERE t1.oid=t2.oid
ORDER BY t2.resource
FOR XML PATH(''), TYPE
).value('.','varchar(max)')
,1,2, ''
) AS Resources
,STUFF(
(
SELECT
',',
CAST(availyid AS VARCHAR)
FROM objectAvail t2
WHERE t1.oid = t2.oId
FOR XML PATH('')
), 1, 1, '') as [Days]
FROM objectresource t1
GROUP BY t1.oid
答案 0 :(得分:0)
我得到了它的工作(:
import csv
def main():
file_contents = []
with open('flights_table_all.csv', 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
file_contents.append(row)
leaders = myfunc(file_contents)
def myfunc(reader):
count = 0
for row in reader:
count = count + 1
print "ONE: " + str(count)
myfunc_two(reader)
def myfunc_two(reader):
count = 0
for row in reader:
count = count + 1
print "TWO: " + str(count)
if __name__ == '__main__':
main()