-1
A
回答
1
您可以使用Pivot语句来做到这一点,正如评论所暗示的那样,但在我看来,使用连接更直接。两次将同一个表加入自己,然后将结果集中的表从三次中选择。如果你的进程是一致的这三个那么我建议这样的:
SELECT a.barcode, a.process as First, a.volume as FirstVolume,
b.process as Second, b.volume as Second Volume,
c.process as Third, c.volume as ThirdVolume
FROM Volumes a
LEFT JOIN Volumes b on b.barcode = a.barcode and b.process = 'BC'
LEFT JOIN Volumes c on c.barcode = a.barcode and c.process = 'FPC'
WHERE a.process = 'PUC';
这使得假定总有一个过程市局...
如果你不知道什么样的价值观可能会在这个过程中柱,我们可以做这样的:
SELECT a.barcode, a.process as First, a.volume as FirstVolume,
b.process as Second, b.volume as Second Volume,
c.process as Third, c.volume as ThirdVolume
FROM Volumes a
LEFT JOIN Volumes b on b.barcode = a.barcode and b.process <> a.process
LEFT JOIN Volumes c on c.barcode = a.barcode and c.process <> a.process and c.process <> b.process;
这不作任何保证第一进程列各行上虽然相同,只有你得到三个不同的流程,每行每一个条形码。
+0
它工作正常......谢谢 – Pallavi
相关问题
- 1. 使用SQL PIVOT行列... SQL Server 2008 R2
- 2. 加入两列两列SQL Server 2008 R2
- 3. 如何在SQL Server 2008 R2的特定位置重新排序和添加列?
- 4. SQL Server 2008 R2中,转换列行和列的列
- 5. sql server 2008 r2中的新行
- 6. SQL Server 2008 R2中的散列表
- 7. SQL Server 2008 R2触发器标识列
- 8. sql server 2008 r2 - 条件伪列
- 9. 在SQL Server 2008 R2中压缩XML列
- 10. 列名无效:SQL Server 2008 R2
- 11. 排列在SQL Server 2008
- 12. 如何在Sql Server 2008 R2中将列转换为行?
- 13. 在假期SQL Server 2008 R2作业重新安排
- 14. SQL Server 2008 R2 Express行号
- 15. 将SQL Server 2008升级到2008 R2
- 16. SQLDependency SQL Server 2008 R2
- 17. SQL Server 2008 R2 OBJECT_ID
- 18. 如何列出角色的成员在SQL Server 2008 R2
- 19. SQL Server 2008 R2 - 如何重命名多列名称?
- 20. SQL Server 2008 R2:使用列值连接别名名称
- 21. SQL Server 2008 R2的动态列名使用
- 22. SQL Server 2008 R2和SQL Server 2008 R2 RTM之间的差异
- 23. 从SQL Server 2008 R2 Express升级到SQL Server 2008 R2企业
- 24. SQL Server 2008 R2表更新XML列修改忽略where子句
- 25. 在SQL Server 2008 R2中更新表的XML列
- 26. Delphi更新SQL Server 2008 R2中的DateTime列
- 27. 用CSV计数使用SQL Server 2008 R2
- 28. 对SQL Server 2008 R2中的某些表无法使用的列的SQL Server intellisense
- 29. 如何将SQL Server 2008 R2数据库还原到SQL Server 2008?
- 30. 的SQL Server 2008 R2/SUM成本
是条形码和流程在所有行中唯一的组合吗? – Segfault
也许[这](http://technet.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx)会给你一个提示.. – Nico
@Nico你能简单解释一下 – Pallavi