SELECT X.*, Y.*
FROM (
SELECT Id, Foo, Bar
FROM (
VALUES ('Id0', 'Foo0', 'Bar0'), ('Id1', 'Foo1', 'Bar1')
) AS AliasTableNameX(Id, Foo, Bar)
) AS X
INNER JOIN (
SELECT *
FROM (
VALUES ('Id1', 'Foo1', 'Bar1', 1), ('Id2', 'Foo2', 'Bar2', 2), ('Id3', 'Foo3', 'Bar3', 3)
) AS AliasTableNameY(Id, Foo, Bar, Price)
) AS Y
ON x.id = y.id
Imports System.Text
Imports System.Data.Common
Imports System.Math
Public Class MathExt
Sub New()
End Sub
'ตัดเศษทิ้งในทุกฯกรณี
''' <summary>
''' ตัดเศษทิ้งทั้งหมด
''' Truncate(1.9999) --> Result = 1
''' </summary>
''' <param name="dblValue"></param>
''' <returns></returns>
''' <remarks>
'''
''' </remarks>
Public Shared Function Truncate(ByVal dblValue As Double) As Double
Return Truncate(dblValue)
End Function
''' <summary>
''' ตัดเศษทิ้งทั้งหมด
''' </summary>
''' <param name="decValue"></param>
''' <returns></returns>
''' <remarks>
''' Example
''' Truncate(1.9999) --> Result =1
''' </remarks>
Public Shared Function Truncate(ByVal decValue As Decimal) As Decimal
Return Truncate(decValue)
End Function
'Truncate a Decimal Number to Some Fixed Decimal Places
'FixDecimal(120.123456, 5) --> 120.12345
''' <summary>
'''
''' </summary>
''' <param name="number"></param>
''' <param name="digits"></param>
''' <returns></returns>
''' <remarks></remarks>
Function FixDecimal(ByVal number As Decimal, ByVal digits As Integer) As Decimal
Dim x As Integer = 10 ^ digits
Return Microsoft.VisualBasic.Conversion.Fix(number * x) / x
'Fix(number) is equivalent to Sign(number) * Int(Abs(number)).
' This code requires Option Strict Off
'Dim MyNumber As Integer
'MyNumber = Int(99.8) ' Returns 99.
'MyNumber = Fix(99.8) ' Returns 99.
'MyNumber = Int(-99.8) ' Returns -100.
'MyNumber = Fix(-99.8) ' Returns -99.
'MyNumber = Int(-99.2) ' Returns -100.
'MyNumber = Fix(-99.2) ' Returns -99.
'MyNumber = CInt(99.8) ' Returns 100.
'MyNumber = CInt(-99.8) ' Returns -100.
'MyNumber = CInt(-99.2) ' Returns -99.
End Function
'Truncate a Double Number to Some Fixed Double Places
''' <summary>
'''
''' </summary>
''' <param name="number"></param>
''' <param name="digits"></param>
''' <returns></returns>
''' <remarks></remarks>
Function FixDouble(ByVal number As Double, ByVal digits As Integer) As Double
Dim x As Integer = 10 ^ digits
Return Microsoft.VisualBasic.Conversion.Fix(number * x) / x
End Function
'ปัดสิบ/ปัด? แบบปัดขึ้นหรือปัดลง เป็นจำนวนเต็ม(Integer) เช่น
' 21 = 20 หรือ 21 = 30 เป็นต้น
''' <summary>
'''
''' </summary>
''' <param name="intValue"></param>
''' <param name="UpDown"></param>
''' <param name="Nearest"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function IntegerNearEst(ByVal intValue As Integer, Optional ByVal UpDown As String = "U", Optional ByVal Nearest As Integer = 10) As Double
'Return If(UpDown.ToUpper() = "U", System.Math.Ceiling(intValue / 10), System.Math.Floor(intValue / 10)) * 10
Return If(UpDown.ToUpper() = "U", System.Math.Ceiling(intValue / Nearest), System.Math.Floor(intValue / Nearest)) * Nearest
End Function
''' <summary>
''' ยามเหงาเราถอนใจ บินไปไม่กลับมา
''' </summary>
''' <typeparam name="T"></typeparam>
''' <param name="list"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetPowerSet(Of T)(ByVal list As IList(Of T)) As IEnumerable(Of IEnumerable(Of T))
Dim x = From m In Enumerable.Range(0, 1 << list.Count)
Select From i In Enumerable.Range(0, list.Count)
Where (m And (1 << i)) <> 0
Select list(i)
Return x
End Function
''' <summary>
''' ภาพอดีตยังงาม ล้ำล้น
''' </summary>
''' <param name="x"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function Factorial(x As Long) As Long
If x <= 1 Then
Return 1
Else
Return x * Factorial(x - 1)
End If
End Function
' การเรียงสับเปลี่ยน
' For Permutation nPr= n!/(n-r)!
''' <summary>
'''
''' </summary>
''' <param name="n"></param>
''' <param name="r"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function Permutation(n As Long, r As Long) As Long
If r = 0 Then
Return 0
End If
If n = 0 Then
Return 0
End If
If (r >= 0) AndAlso (r <= n) Then
Return Factorial(n) \ Factorial(n - r)
Else
Return 0
End If
End Function
'การจัดกลุ่ม
'For Combination nCr=n!/(n-r)!r!
''' <summary>
'''
''' </summary>
''' <param name="a"></param>
''' <param name="b"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function Combination(a As Long, b As Long) As Long
If a <= 1 Then
Return 1
End If
Return Factorial(a) \ (Factorial(b) * Factorial(a - b))
End Function
End Class
' The example displays the following output to the console:
' Value Ceiling Floor
'
' 7.03 8 7
' 7.64 8 7
' 0.12 1 0
' -0.12 0 -1
' -7.1 -7 -8
' -7.6 -7 -8
'ปัดเศษขึ้น ให้เป็นจำนวนเต็ม
'System.Math.Ceiling
'ปัดเศษลง ให้เป็นจำนวนเต็ม
'System.Math.Floor
'ปัดเศษ ขึ้นก็ได้/ลงก็ได้
'Round() Rounds a value to the nearest integer or to the specified number of fractional digits.