1
我有一個表名爲calcu
SQL列計算mininimum值
id date name s1 s2 s3 s4 min_value
1 10/10/2017 dicky 7 4 8 9 [4]
2 10/10/2017 acton 12 15 17 19 [15]
3 10/10/2017 adney 28 13 19 14 [13]
------------------------------------------------------------------
when total by date 47 32 44 42
這裏作爲最小的列的值是s2
[32],這就是爲什麼s2
值= min_value
柱。
現在是沒有問題的。但是,如果s1, s2, s3, s4
值中的任何字段的值等於[see below example
]並且包含任何字段,則min_value字段會翻倍並且所有列翻倍。 實施例:
id date name s1 s2 s3 s4 min_value
1 10/10/2017 dicky 7 24 8 11 [8]/[11]
2 10/10/2017 acton 12 15 17 19 [17]/[19]
3 10/10/2017 adney 28 13 19 14 [19]/[14]
------------------------------------------------------------------
when total by date 47 52 44 44
這裏最小值列s3
ANS s4
,
我需要s3 or s4
內它意味着要麼s3
或s4
列將在min_value
柱被填充任何列。
see the problem here with sqlfiddle
我使用MySQL。
您的問題沒有明確的.. – scaisEdge
你試圖**'GROUP BY' **你的結果,或選擇**'DISTINCT' **值? – AlexCode
第1步。以日期存儲日期。然後回到我們身邊。 – Strawberry