1
我面临着相当令人头疼的问题。在查询中合并记录的列
我有一张表,结构如下。
coursename - day1 - moment1 - day2 - moment2 - day3 - moment3 - day4 - moment4
course A - mon - morning - wed - afternoon - NULL - NULL - NULL - NULL
course B - tue - evening - thu - evening - NULL - NULL - NULL - NULL
course C - mon - evening - tue - evening - wed - morning - thu - evening
course D - wed - morning - thu - morning - sat - afternoon- NULL - NULL
输出应该
coursename - timetable
course A - mon morning, wed afternoon
course B - tue/thu evening
course C - mon/tue/thu evening, wed morning
course D - wed/thu morning, sat afternoon
我将如何去查询类似的东西?我唯一能想到的就是使用嵌套的情况,但是恐怕会杀死性能。
我使用MS SQL Server 2012的
老实说,我会在前端做格式化,让数据库做它擅长的。然而,这就是说,你可能会用它来标准化你的桌子,这会让生活更轻松。 –