Sql server 2005 TSQL集合论
问题是 你要用数字标记骰子的边。每个骰子有6个边。你有两个骰子。您必须添加标签,以便不显示0到31之间的数字的总和或乘积。完整输出:Sql server 2005 TSQL集合论,sql-server-2005,Sql Server 2005,问题是 你要用数字标记骰子的边。每个骰子有6个边。你有两个骰子。您必须添加标签,以便不显示0到31之间的数字的总和或乘积。完整输出: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 我试过了 (select 0 as dice1 union select 1 union select 2 union
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
我试过了
(select
0 as dice1 union
select 1 union
select 2 union
select 3 union
select 4 union
select 5 )
join
(select
0 as dice2 union
select 1 union
select 2 union
select 3 union
select 4 union
select 5 )
我不知道如何进一步处理它。非常感谢您的帮助。正如马丁在评论中提到的,解决这个问题的关键是使用颠倒的6表示9。见: 对于编程T-SQL解决方案,可能:
declare @Dice1 table (
side int
)
insert into @Dice1
(side)
select 0 union all
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5
declare @Dice2 table (
side int
)
insert into @Dice2
(side)
select 0 union all
select 1 union all
select 2 union all
select 6 union all
select 7 union all
select 8 union all
select 9 /* Upside down 6 */
select CAST(d1.side as CHAR(1)) + CAST(d2.side as CHAR(1)) as MyDate
from @Dice1 d1
cross join @Dice2 d2
where d1.side * 10 + d2.side <= 31
union
select CAST(d2.side as CHAR(1)) + CAST(d1.side as CHAR(1)) as MyDate
from @Dice1 d1
cross join @Dice2 d2
where d2.side * 10 + d1.side <= 31
order by MyDate
不知道。你肯定需要在一个或另一个骰子上使用6,7,8,9。但是0,1和2需要在两个骰子上,这只为7个数字留下6个槽!也许你得把6倒过来才能得到9。无论如何,与SQLServer2005无关!你有时会在银行看到由木块制成的连续压延机,这是实现的典型问题。这个问题是严格的过约束问题,正如@Martin所建议的那样,用6/9模糊度来解决。但无论如何,这不是一个编程问题,也不是一个话题。非常优雅的解决方案。是01 2 3 4 5和01 2 7 8 6。@Denis:喝了多年的Microsoft Kool Aid:我的文档,我的下载,…,我的日期:-哈哈,但这些是数字,不是日期!