ROUND SQL function


1. Usage of ROUND to round the unit price.

SQL Server Query 1

            
SELECT  
ProductID, ProductName, UnitPrice,
ROUND(UnitPrice, 2) AS RoundedUnitPrice
FROM Products
ORDER BY ProductID;

Create SQL query with SqlQueryBuilder 1

            
var (sql1, parameters1) = new SqlQueryBuilder()  
.Select().Columns("ProductID", "ProductName", "UnitPrice")
.Column(new ROUND(new Column("UnitPrice"), 2), "RoundedUnitPrice")
.From("Products")
.OrderBy(new OrderBy().Set(new Column("ProductID")))
.Build();

Query build by SqlQueryBuilder 1

            
SELECT ProductID,
       ProductName,
       UnitPrice,
       ROUND(UnitPrice, @pMAIN_2507200213501886950, @pMAIN_2507200213501886951) AS RoundedUnitPrice
FROM Products
ORDER BY ProductID ASC;


            
        

Parameters (If used)

Name Value
@pMAIN_2507200213501886950 2
@pMAIN_2507200213501886951 0

Query Results 1:

  ProductID ProductName UnitPrice RoundedUnitPrice
1 1 Chai 18.0000 18.0000
2 2 Chang 19.0000 19.0000
3 3 Aniseed Syrup 10.0000 10.0000
4 4 Chef Anton's Cajun Seasoning 22.0000 22.0000
5 5 Chef Anton's Gumbo Mix 21.3500 21.3500
6 6 Grandma's Boysenberry Spread 25.0000 25.0000
7 7 Uncle Bob's Organic Dried Pears 30.0000 30.0000
8 8 Northwoods Cranberry Sauce 40.0000 40.0000
9 9 Mishi Kobe Niku 97.0000 97.0000
10 10 Ikura 31.0000 31.0000
11 11 Queso Cabrales 21.0000 21.0000
12 12 Queso Manchego La Pastora 38.0000 38.0000
13 13 Konbu 6.0000 6.0000
14 14 Tofu 23.2500 23.2500
15 15 Genen Shouyu 15.5000 15.5000
16 16 Pavlova 17.4500 17.4500
17 17 Alice Mutton 39.0000 39.0000
18 18 Carnarvon Tigers 62.5000 62.5000
19 19 Teatime Chocolate Biscuits 9.2000 9.2000
20 20 Sir Rodney's Marmalade 81.0000 81.0000
21 21 Sir Rodney's Scones 10.0000 10.0000
22 22 Gustaf's Knäckebröd 21.0000 21.0000
23 23 Tunnbröd 9.0000 9.0000
24 24 Guaraná Fantástica 4.5000 4.5000
25 25 NuNuCa Nuß-Nougat-Creme 14.0000 14.0000
26 26 Gumbär Gummibärchen 31.2300 31.2300
27 27 Schoggi Schokolade 43.9000 43.9000
28 28 Rössle Sauerkraut 45.6000 45.6000
29 29 Thüringer Rostbratwurst 123.7900 123.7900
30 30 Nord-Ost Matjeshering 25.8900 25.8900
31 31 Gorgonzola Telino 12.5000 12.5000
32 32 Mascarpone Fabioli 32.0000 32.0000
33 33 Geitost 2.5000 2.5000
34 34 Sasquatch Ale 14.0000 14.0000
35 35 Steeleye Stout 18.0000 18.0000
36 36 Inlagd Sill 19.0000 19.0000
37 37 Gravad lax 26.0000 26.0000
38 38 Côte de Blaye 263.5000 263.5000
39 39 Chartreuse verte 18.0000 18.0000
40 40 Boston Crab Meat 18.4000 18.4000
41 41 Jack's New England Clam Chowder 9.6500 9.6500
42 42 Singaporean Hokkien Fried Mee 14.0000 14.0000
43 43 Ipoh Coffee 46.0000 46.0000
44 44 Gula Malacca 19.4500 19.4500
45 45 Rogede sild 9.5000 9.5000
46 46 Spegesild 12.0000 12.0000
47 47 Zaanse koeken 9.5000 9.5000
48 48 Chocolade 12.7500 12.7500
49 49 Maxilaku 20.0000 20.0000
50 50 Valkoinen suklaa 16.2500 16.2500
51 51 Manjimup Dried Apples 53.0000 53.0000
52 52 Filo Mix 7.0000 7.0000
53 53 Perth Pasties 32.8000 32.8000
54 54 Tourtière 7.4500 7.4500
55 55 Pâté chinois 24.0000 24.0000
56 56 Gnocchi di nonna Alice 38.0000 38.0000
57 57 Ravioli Angelo 19.5000 19.5000
58 58 Escargots de Bourgogne 13.2500 13.2500
59 59 Raclette Courdavault 55.0000 55.0000
60 60 Camembert Pierrot 34.0000 34.0000
61 61 Sirop d'érable 28.5000 28.5000
62 62 Tarte au sucre 49.3000 49.3000
63 63 Vegie-spread 43.9000 43.9000
64 64 Wimmers gute Semmelknödel 33.2500 33.2500
65 65 Louisiana Fiery Hot Pepper Sauce 21.0500 21.0500
66 66 Louisiana Hot Spiced Okra 17.0000 17.0000
67 67 Laughing Lumberjack Lager 14.0000 14.0000
68 68 Scottish Longbreads 12.5000 12.5000
69 69 Gudbrandsdalsost 36.0000 36.0000
70 70 Outback Lager 15.0000 15.0000
71 71 Flotemysost 21.5000 21.5000
72 72 Mozzarella di Giovanni 34.8000 34.8000
73 73 Röd Kaviar 15.0000 15.0000
74 74 Longlife Tofu 10.0000 10.0000
75 75 Rhönbräu Klosterbier 7.7500 7.7500
76 76 Lakkalikööri 18.0000 18.0000
77 77 Original Frankfurter grüne Soße 13.0000 13.0000


2. Usage of ROUND to round the total order cost.

SQL Server Query 2

            
SELECT  
od.OrderID,
SUM(od.Quantity * od.UnitPrice * (1 - od.Discount)) AS OrderTotal,
ROUND(SUM(od.Quantity * od.UnitPrice * (1 - od.Discount)), 2) AS RoundedOrderTotal
FROM [Order Details] od
GROUP BY od.OrderID
ORDER BY od.OrderID;

Create SQL query with SqlQueryBuilder 2

            
var (sql2, parameters2) = new SqlQueryBuilder()  
.Select().Column("od.OrderID", "OrderID")
.Column(new SUM(new ColumnArithmatic("od.Quantity").MULTIPLY("od.UnitPrice")
.MULTIPLY().StartBracket(1).SUBTRACT("od.Discount").EndBracket()), "OrderTotal")
.Column(new ROUND(new SUM(new ColumnArithmatic("od.Quantity").MULTIPLY("od.UnitPrice")
.MULTIPLY().StartBracket(1).SUBTRACT("od.Discount").EndBracket()), 2), "RoundedOrderTotal")
.From("[Order Details]", "od")
.GroupBy(new GroupBy(new Column("od.OrderID")))
.OrderBy(new OrderBy().SetColumnAscending("od.OrderID"))
.Build();

Query build by SqlQueryBuilder 2

            
SELECT od.OrderID AS OrderID,
       SUM(od.Quantity * od.UnitPrice * (@pMAIN_2507200213501946740 - od.Discount)) AS OrderTotal,
       ROUND(SUM(od.Quantity * od.UnitPrice * (@pMAIN_2507200213501946741 - od.Discount)), @pMAIN_2507200213501946742, @pMAIN_2507200213501946743) AS RoundedOrderTotal
FROM [Order Details] AS od
GROUP BY od.OrderID
ORDER BY od.OrderID ASC;


            
        

Parameters (If used)

Name Value
@pMAIN_2507200213501946740 1
@pMAIN_2507200213501946741 1
@pMAIN_2507200213501946742 2
@pMAIN_2507200213501946743 0

Query Results 2:

  OrderID OrderTotal RoundedOrderTotal
1 10248 440 440
2 10249 1863.3999938964844 1863.4
3 10250 1552.6000366210938 1552.6
4 10251 654.0600051879883 654.06
5 10252 3597.89990234375 3597.9
6 10253 1444.7999877929688 1444.8
7 10254 556.6200332641602 556.62
8 10255 2490.5 2490.5
9 10256 517.8000030517578 517.8
10 10257 1119.900001525879 1119.9
11 10258 1614.8800048828125 1614.88
12 10259 100.79999923706055 100.8
13 10260 1504.6499938964844 1504.65
14 10261 448 448
15 10262 583.9999961853027 584
16 10263 1873.8000030517578 1873.8
17 10264 695.625 695.63
18 10265 1176 1176
19 10266 346.55999755859375 346.56
20 10267 3536.6000061035156 3536.6
21 10268 1101.1999969482422 1101.2
22 10269 642.2000122070312 642.2
23 10270 1376 1376
24 10271 48 48
25 10272 1456 1456
26 10273 2037.2799682617188 2037.28
27 10274 538.6000061035156 538.6
28 10275 291.84000396728516 291.84
29 10276 420 420
30 10277 1200.7999877929688 1200.8
31 10278 1488.7999877929688 1488.8
32 10279 351 351
33 10280 613.2000007629395 613.2
34 10281 86.49999904632568 86.5
35 10282 155.39999771118164 155.4
36 10283 1414.7999954223633 1414.8
37 10284 1170.375 1170.38
38 10285 1743.3600158691406 1743.36
39 10286 3016 3016
40 10287 819.0000076293945 819
41 10288 80.0999984741211 80.1
42 10289 479.3999938964844 479.4
43 10290 2169 2169
44 10291 497.51998138427734 497.52
45 10292 1296 1296
46 10293 848.7000007629395 848.7
47 10294 1887.600025177002 1887.6
48 10295 121.5999984741211 121.6
49 10296 1050.6000061035156 1050.6
50 10297 1420 1420
51 10298 2645 2645
52 10299 349.5 349.5
53 10300 608 608
54 10301 755 755
55 10302 2708.800018310547 2708.8
56 10303 1117.7999877929688 1117.8
57 10304 954.4000015258789 954.4
58 10305 3741.2999877929688 3741.3
59 10306 498.5 498.5
60 10307 424 424
61 10308 88.79999923706055 88.8
62 10309 1761.9999980926514 1762
63 10310 336 336
64 10311 268.8000030517578 268.8
65 10312 1614.8000183105469 1614.8
66 10313 182.39999389648438 182.4
67 10314 2094.2999572753906 2094.3
68 10315 516.8000030517578 516.8
69 10316 2835 2835
70 10317 288 288
71 10318 240.4000015258789 240.4
72 10319 1191.2000122070312 1191.2
73 10320 516 516
74 10321 144 144
75 10322 112 112
76 10323 164.39999771118164 164.4
77 10324 5275.715103149414 5275.72
78 10325 1496.9999923706055 1497
79 10326 982 982
80 10327 1810.0000457763672 1810
81 10328 1168 1168
82 10329 4578.429954528809 4578.43
83 10330 1649 1649
84 10331 88.5 88.5
85 10332 1786.879997253418 1786.88
86 10333 877.2000122070312 877.2
87 10334 144.79999923706055 144.8
88 10335 2036.160041809082 2036.16
89 10336 285.1199951171875 285.12
90 10337 2467 2467
91 10338 934.5 934.5
92 10339 3354 3354
93 10340 2436.1800231933594 2436.18
94 10341 352.6000061035156 352.6
95 10342 1840.6400146484375 1840.64
96 10343 1584 1584
97 10344 2296 2296
98 10345 2924.800003051758 2924.8
99 10346 1618.8799438476562 1618.88
100 10347 814.420000076294 814.42
101 10348 363.6000061035156 363.6
102 10349 141.60000610351562 141.6
103 10350 642.0599975585938 642.06
104 10351 5398.724891662598 5398.72
105 10352 136.3000030517578 136.3
106 10353 8593.280014038086 8593.28
107 10354 568.8000030517578 568.8
108 10355 480 480
109 10356 1106.3999938964844 1106.4
110 10357 1167.6800079345703 1167.68
111 10358 429.3999900817871 429.4
112 10359 3471.6799926757812 3471.68
113 10360 7390.199996948242 7390.2
114 10361 2046.239990234375 2046.24
115 10362 1549.6000061035156 1549.6
116 10363 447.2000045776367 447.2
117 10364 950 950
118 10365 403.20001220703125 403.2
119 10366 136 136
120 10367 834.2000122070312 834.2
121 10368 1689.7799682617188 1689.78
122 10369 2390.4000244140625 2390.4
123 10370 1117.6000061035156 1117.6
124 10371 72.95999908447266 72.96
125 10372 9210.89990234375 9210.9
126 10373 1366.4000244140625 1366.4
127 10374 459 459
128 10375 338 338
129 10376 399 399
130 10377 863.5999908447266 863.6
131 10378 103.19999694824219 103.2
132 10379 863.2799644470215 863.28
133 10380 1313.8199615478516 1313.82
134 10381 112 112
135 10382 2900 2900
136 10383 899 899
137 10384 2222.4000244140625 2222.4
138 10385 691.2000122070312 691.2
139 10386 166 166
140 10387 1058.3999938964844 1058.4
141 10388 1228.8000030517578 1228.8
142 10389 1832.7999877929688 1832.8
143 10390 2090.8799438476562 2090.88
144 10391 86.4000015258789 86.4
145 10392 1440 1440
146 10393 2556.9500274658203 2556.95
147 10394 442 442
148 10395 2122.919952392578 2122.92
149 10396 1903.7999877929688 1903.8
150 10397 716.7200317382812 716.72
151 10398 2505.599853515625 2505.6
152 10399 1765.6000061035156 1765.6
153 10400 3063 3063
154 10401 3868.6000061035156 3868.6
155 10402 2713.5 2713.5
156 10403 855.0150299072266 855.02
157 10404 1591.2499694824219 1591.25
158 10405 400 400
159 10406 1830.780044555664 1830.78
160 10407 1194 1194
161 10408 1622.400001525879 1622.4
162 10409 319.1999969482422 319.2
163 10410 802 802
164 10411 966.8000183105469 966.8
165 10412 334.79998779296875 334.8
166 10413 2123.2000122070312 2123.2
167 10414 224.82999420166016 224.83
168 10415 102.4000015258789 102.4
169 10416 720 720
170 10417 11188.400000572205 11188.4
171 10418 1814.7999877929688 1814.8
172 10419 2097.6000366210938 2097.6
173 10420 1707.8399209976196 1707.84
174 10421 1194.2700214385986 1194.27
175 10422 49.79999923706055 49.8
176 10423 1020 1020
177 10424 9194.560363769531 9194.56
178 10425 360 360
179 10426 338.1999969482422 338.2
180 10427 651 651
181 10428 192 192
182 10429 1441.375 1441.38
183 10430 4899.2000732421875 4899.2
184 10431 1892.25 1892.25
185 10432 485 485
186 10433 851.2000122070312 851.2
187 10434 321.1200256347656 321.12
188 10435 631.6000061035156 631.6
189 10436 1994.5199737548828 1994.52
190 10437 393 393
191 10438 453.99999237060547 454
192 10439 1078 1078
193 10440 4924.135192871094 4924.14
194 10441 1755 1755
195 10442 1792 1792
196 10443 517.4399948120117 517.44
197 10444 1031.6999969482422 1031.7
198 10445 174.9000015258789 174.9
199 10446 246.239990234375 246.24
200 10447 914.4000015258789 914.4
201 10448 443.3999938964844 443.4
202 10449 1838.2000122070312 1838.2
203 10450 425.1200199127197 425.12
204 10451 3849.6597900390625 3849.66
205 10452 2018.5 2018.5
206 10453 407.6999969482422 407.7
207 10454 331.20001220703125 331.2
208 10455 2684 2684
209 10456 557.6000061035156 557.6
210 10457 1584 1584
211 10458 3891 3891
212 10459 1659.1999816894531 1659.2
213 10460 176.0999984741211 176.1
214 10461 1538.6999816894531 1538.7
215 10462 155.99999713897705 156
216 10463 713.3000030517578 713.3
217 10464 1609.2800521850586 1609.28
218 10465 2517.9999237060547 2518
219 10466 216 216
220 10467 235.1999969482422 235.2
221 10468 717.6000061035156 717.6
222 10469 956.675012588501 956.68
223 10470 1820.8000030517578 1820.8
224 10471 1328 1328
225 10472 1036.8000183105469 1036.8
226 10473 230.39999389648438 230.4
227 10474 1249.1000213623047 1249.1
228 10475 1505.1800537109375 1505.18
229 10476 180.47999954223633 180.48
230 10477 558 558
231 10478 471.1999816894531 471.2
232 10479 10495.599975585938 10495.6
233 10480 756 756
234 10481 1472 1472
235 10482 147 147
236 10483 668.7999877929688 668.8
237 10484 386.1999969482422 386.2
238 10485 1583.9999694824219 1584
239 10486 1272 1272
240 10487 889.7000045776367 889.7
241 10488 1512 1512
242 10489 439.1999969482422 439.2
243 10490 3163.199996948242 3163.2
244 10491 259.5050048828125 259.51
245 10492 851.1999664306641 851.2
246 10493 608.3999633789062 608.4
247 10494 912 912
248 10495 278 278
249 10496 190 190
250 10497 1380.6000061035156 1380.6
251 10498 575 575
252 10499 1412 1412
253 10500 523.2599945068359 523.26
254 10501 149 149
255 10502 816.3000030517578 816.3
256 10503 2048.5 2048.5
257 10504 1388.5 1388.5
258 10505 147.89999389648438 147.9
259 10506 415.79998779296875 415.8
260 10507 749.0625 749.06
261 10508 240 240
262 10509 136.8000030517578 136.8
263 10510 4707.539932250977 4707.54
264 10511 2550 2550
265 10512 525.3000221252441 525.3
266 10513 1942 1942
267 10514 8623.450012207031 8623.45
268 10515 9921.300170898438 9921.3
269 10516 2381.0499877929688 2381.05
270 10517 352 352
271 10518 4150.050003051758 4150.05
272 10519 2314.199981689453 2314.2
273 10520 200 200
274 10521 225.5 225.5
275 10522 2318.239990234375 2318.24
276 10523 2444.3099822998047 2444.31
277 10524 3192.6499938964844 3192.65
278 10525 818.3999938964844 818.4
279 10526 1151.400001525879 1151.4
280 10527 1503 1503
281 10528 392.20001220703125 392.2
282 10529 946 946
283 10530 4180 4180
284 10531 110 110
285 10532 796.3500061035156 796.35
286 10533 2222.2000122070312 2222.2
287 10534 465.6999931335449 465.7
288 10535 1940.8499908447266 1940.85
289 10536 1645 1645
290 10537 1823.7999877929688 1823.8
291 10538 139.79999923706055 139.8
292 10539 355.5 355.5
293 10540 10191.699951171875 10191.7
294 10541 1946.5199279785156 1946.52
295 10542 469.11000061035156 469.11
296 10543 1504.5 1504.5
297 10544 417.20001220703125 417.2
298 10545 210 210
299 10546 2812 2812
300 10547 1792.800048828125 1792.8
301 10548 240.10000610351562 240.1
302 10549 3554.275146484375 3554.28
303 10550 683.2999877929688 683.3
304 10551 1677.2999877929688 1677.3
305 10552 880.5 880.5
306 10553 1546.3000030517578 1546.3
307 10554 1728.5249938964844 1728.52
308 10555 2944.4000091552734 2944.4
309 10556 835.2000122070312 835.2
310 10557 1152.5 1152.5
311 10558 2142.9000244140625 2142.9
312 10559 520.4099960327148 520.41
313 10560 1072.4249877929688 1072.42
314 10561 2844.5 2844.5
315 10562 488.6999816894531 488.7
316 10563 965 965
317 10564 1234.0499877929688 1234.05
318 10565 639.8999633789062 639.9
319 10566 1761 1761
320 10567 2519 2519
321 10568 155 155
322 10569 890 890
323 10570 2465.25 2465.25
324 10571 550.5875244140625 550.59
325 10572 1501.0849914550781 1501.08
326 10573 2082 2082
327 10574 764.2999992370605 764.3
328 10575 2147.3999938964844 2147.4
329 10576 838.4500122070312 838.45
330 10577 569 569
331 10578 477 477
332 10579 317.75 317.75
333 10580 1013.744987487793 1013.74
334 10581 310 310
335 10582 330 330
336 10583 2237.5000610351562 2237.5
337 10584 593.75 593.75
338 10585 142.5 142.5
339 10586 23.80000114440918 23.8
340 10587 807.3800048828125 807.38
341 10588 3120 3120
342 10589 72 72
343 10590 1101 1101
344 10591 812.5 812.5
345 10592 516.4674987792969 516.47
346 10593 1994.4000511169434 1994.4
347 10594 565.5 565.5
348 10595 4725 4725
349 10596 1180.8800048828125 1180.88
350 10597 718.0800018310547 718.08
351 10598 2388.5 2388.5
352 10599 493 493
353 10600 479.79999923706055 479.8
354 10601 2285 2285
355 10602 48.75 48.75
356 10603 1483 1483
357 10604 230.8499984741211 230.85
358 10605 4109.699981689453 4109.7
359 10606 1130.3999938964844 1130.4
360 10607 6475.399993896484 6475.4
361 10608 1064 1064
362 10609 424 424
363 10610 299.25 299.25
364 10611 808 808
365 10612 6375 6375
366 10613 353.1999969482422 353.2
367 10614 464 464
368 10615 120 120
369 10616 4807 4807
370 10617 1402.5 1402.5
371 10618 2697.5 2697.5
372 10619 1260 1260
373 10620 57.5 57.5
374 10621 758.5 758.5
375 10622 560 560
376 10623 1336.9499969482422 1336.95
377 10624 1393.239990234375 1393.24
378 10625 479.75 479.75
379 10626 1503.6000061035156 1503.6
380 10627 1185.75 1185.75
381 10628 450 450
382 10629 2775.050048828125 2775.05
383 10630 903.6000061035156 903.6
384 10631 55.79999923706055 55.8
385 10632 589 589
386 10633 5510.592788696289 5510.59
387 10634 4985.5 4985.5
388 10635 1326.2250061035156 1326.23
389 10636 629.5 629.5
390 10637 2761.9375 2761.94
391 10638 2720.0499877929688 2720.05
392 10639 500 500
393 10640 708.75 708.75
394 10641 2054 2054
395 10642 696 696
396 10643 814.5 814.5
397 10644 1371.7999877929688 1371.8
398 10645 1535 1535
399 10646 1446 1446
400 10647 636 636
401 10648 372.375 372.38
402 10649 1434 1434
403 10650 1779.2000122070312 1779.2
404 10651 397.8000030517578 397.8
405 10652 318.83499908447266 318.83
406 10653 1083.1499938964844 1083.15
407 10654 601.8299903869629 601.83
408 10655 154.40000915527344 154.4
409 10656 604.2149505615234 604.21
410 10657 4371.600006103516 4371.6
411 10658 4464.5999755859375 4464.6
412 10659 1227.0199890136719 1227.02
413 10660 1701 1701
414 10661 562.600025177002 562.6
415 10662 125 125
416 10663 1930.3999633789062 1930.4
417 10664 1288.3875427246094 1288.39
418 10665 1295 1295
419 10666 4666.93994140625 4666.94
420 10667 1536.8000030517578 1536.8
421 10668 625.2749938964844 625.27
422 10669 570 570
423 10670 2301.75 2301.75
424 10671 920.1000061035156 920.1
425 10672 3815.25 3815.25
426 10673 412.3499984741211 412.35
427 10674 45 45
428 10675 1423 1423
429 10676 534.8500137329102 534.85
430 10677 813.3650512695312 813.37
431 10678 5256.5 5256.5
432 10679 660 660
433 10680 1261.875 1261.88
434 10681 1287.3999938964844 1287.4
435 10682 375.5 375.5
436 10683 63 63
437 10684 1768 1768
438 10685 801.0999984741211 801.1
439 10686 1404.4500122070312 1404.45
440 10687 4960.9000244140625 4960.9
441 10688 3160.599884033203 3160.6
442 10689 472.5 472.5
443 10690 862.5 862.5
444 10691 10164.799987792969 10164.8
445 10692 878 878
446 10693 2071.2000122070312 2071.2
447 10694 4825 4825
448 10695 642 642
449 10696 996 996
450 10697 805.4250030517578 805.43
451 10698 3436.4434509277344 3436.44
452 10699 114 114
453 10700 1638.4000091552734 1638.4
454 10701 2864.5 2864.5
455 10702 330 330
456 10703 2545 2545
457 10704 595.5 595.5
458 10705 378 378
459 10706 1893 1893
460 10707 1641 1641
461 10708 180.4000015258789 180.4
462 10709 3424 3424
463 10710 93.5 93.5
464 10711 4451.699989318848 4451.7
465 10712 1233.4800033569336 1233.48
466 10713 2827.9000244140625 2827.9
467 10714 2205.75 2205.75
468 10715 1296 1296
469 10716 706 706
470 10717 1270.75 1270.75
471 10718 3463 3463
472 10719 844.252498626709 844.25
473 10720 550 550
474 10721 923.875 923.88
475 10722 1570 1570
476 10723 468.45001220703125 468.45
477 10724 638.5 638.5
478 10725 287.8000030517578 287.8
479 10726 655 655
480 10727 1624.5 1624.5
481 10728 1296.7500076293945 1296.75
482 10729 1850 1850
483 10730 484.2624816894531 484.26
484 10731 1890.5 1890.5
485 10732 360 360
486 10733 1459 1459
487 10734 1498.3500061035156 1498.35
488 10735 536.3999996185303 536.4
489 10736 997 997
490 10737 139.8000030517578 139.8
491 10738 52.349998474121094 52.35
492 10739 240 240
493 10740 1416.000015258789 1416
494 10741 228 228
495 10742 3118 3118
496 10743 319.1999816894531 319.2
497 10744 736 736
498 10745 4529.800018310547 4529.8
499 10746 2311.7000122070312 2311.7
500 10747 1912.8500061035156 1912.85
501 10748 2196 2196
502 10749 1080 1080
503 10750 1590.5625 1590.56
504 10751 1631.4840087890625 1631.48
505 10752 252 252
506 10753 88 88
507 10754 55.20000076293945 55.2
508 10755 1948.5 1948.5
509 10756 1990 1990
510 10757 3082 3082
511 10758 1644.5999755859375 1644.6
512 10759 320 320
513 10760 2917 2917
514 10761 507 507
515 10762 4337 4337
516 10763 616 616
517 10764 2286 2286
518 10765 1515.5999755859375 1515.6
519 10766 2310 2310
520 10767 28 28
521 10768 1477 1477
522 10769 1684.2749938964844 1684.27
523 10770 236.25 236.25
524 10771 344 344
525 10772 3603.219970703125 3603.22
526 10773 2030.400001525879 2030.4
527 10774 868.75 868.75
528 10775 228 228
529 10776 6635.274993896484 6635.27
530 10777 224 224
531 10778 96.5 96.5
532 10779 1335 1335
533 10780 720 720
534 10781 975.8800010681152 975.88
535 10782 12.5 12.5
536 10783 1442.5 1442.5
537 10784 1488.0000247955322 1488
538 10785 387.5 387.5
539 10786 1531.0800170898438 1531.08
540 10787 2622.760009765625 2622.76
541 10788 731.5 731.5
542 10789 3687 3687
543 10790 722.5 722.5
544 10791 1829.7569732666016 1829.76
545 10792 399.8500003814697 399.85
546 10793 191.10000610351562 191.1
547 10794 314.76000213623047 314.76
548 10795 2158 2158
549 10796 2341.364013671875 2341.36
550 10797 420 420
551 10798 446.5999984741211 446.6
552 10799 1553.5 1553.5
553 10800 1468.935001373291 1468.94
554 10801 3026.85009765625 3026.85
555 10802 2942.8125 2942.81
556 10803 1193.009994506836 1193.01
557 10804 2278.4000244140625 2278.4
558 10805 2775 2775
559 10806 439.5999984741211 439.6
560 10807 18.399999618530273 18.4
561 10808 1411 1411
562 10809 140 140
563 10810 187 187
564 10811 852 852
565 10812 1692.7999267578125 1692.8
566 10813 602.4000091552734 602.4
567 10814 1788.4500045776367 1788.45
568 10815 40 40
569 10816 8446.450012207031 8446.45
570 10817 10952.844970703125 10952.84
571 10818 833 833
572 10819 477 477
573 10820 1140 1140
574 10821 678 678
575 10822 237.89999389648438 237.9
576 10823 2826 2826
577 10824 250.8000030517578 250.8
578 10825 1030.760009765625 1030.76
579 10826 730 730
580 10827 843 843
581 10828 932 932
582 10829 1764 1764
583 10830 1974 1974
584 10831 2684.3999996185303 2684.4
585 10832 475.1100072860718 475.11
586 10833 906.9299926757812 906.93
587 10834 1432.7139892578125 1432.71
588 10835 845.8000011444092 845.8
589 10836 4705.5 4705.5
590 10837 1064.5 1064.5
591 10838 1938.375 1938.38
592 10839 827.5499877929688 827.55
593 10840 211.20000457763672 211.2
594 10841 4581 4581
595 10842 975 975
596 10843 159 159
597 10844 735 735
598 10845 3812.7000122070312 3812.7
599 10846 1112 1112
600 10847 4931.92000579834 4931.92
601 10848 931.5 931.5
602 10849 967.8190307617188 967.82
603 10850 629 629
604 10851 2603 2603
605 10852 2984 2984
606 10853 625 625
607 10854 2966.5 2966.5
608 10855 2227.8875122070312 2227.89
609 10856 660 660
610 10857 2048.2125854492188 2048.21
611 10858 649 649
612 10859 1078.6875 1078.69
613 10860 519 519
614 10861 3523.3999938964844 3523.4
615 10862 581 581
616 10863 441.15000915527344 441.15
617 10864 282 282
618 10865 16387.5 16387.5
619 10866 1096.199951171875 1096.2
620 10867 98.4000015258789 98.4
621 10868 1920.5999755859375 1920.6
622 10869 1630 1630
623 10870 160 160
624 10871 1979.22998046875 1979.23
625 10872 2058.459991455078 2058.46
626 10873 336.8000030517578 336.8
627 10874 310 310
628 10875 709.5499877929688 709.55
629 10876 917 917
630 10877 1955.125 1955.13
631 10878 1539 1539
632 10879 611.3000030517578 611.3
633 10880 1500 1500
634 10881 150 150
635 10882 892.6399993896484 892.64
636 10883 36 36
637 10884 1378.0699768066406 1378.07
638 10885 1209 1209
639 10886 3127.5 3127.5
640 10887 70 70
641 10888 605 605
642 10889 11380 11380
643 10890 860.1000061035156 860.1
644 10891 368.9324951171875 368.93
645 10892 2090 2090
646 10893 5502.1099853515625 5502.11
647 10894 2753.0999908447266 2753.1
648 10895 6379.4000244140625 6379.4
649 10896 750.5 750.5
650 10897 10835.240173339844 10835.24
651 10898 30 30
652 10899 122.4000015258789 122.4
653 10900 33.75 33.75
654 10901 934.5 934.5
655 10902 863.4299926757812 863.43
656 10903 932.0499877929688 932.05
657 10904 1924.25 1924.25
658 10905 342 342
659 10906 427.5 427.5
660 10907 108.5 108.5
661 10908 663.0999984741211 663.1
662 10909 670 670
663 10910 452.9000015258789 452.9
664 10911 858 858
665 10912 6200.5498046875 6200.55
666 10913 768.75 768.75
667 10914 537.5 537.5
668 10915 539.5 539.5
669 10916 686.6999969482422 686.7
670 10917 365.88999938964844 365.89
671 10918 1447.5 1447.5
672 10919 1122.7999877929688 1122.8
673 10920 390 390
674 10921 1936 1936
675 10922 742.5 742.5
676 10923 748.8000183105469 748.8
677 10924 1835.699951171875 1835.7
678 10925 475.1500015258789 475.15
679 10926 514.4000015258789 514.4
680 10927 800 800
681 10928 137.5 137.5
682 10929 1174.75 1174.75
683 10930 2255.5 2255.5
684 10931 799.2000122070312 799.2
685 10932 1788.6299743652344 1788.63
686 10933 920.5999984741211 920.6
687 10934 500 500
688 10935 619.5 619.5
689 10936 456 456
690 10937 644.7999877929688 644.8
691 10938 2731.875 2731.88
692 10939 637.5 637.5
693 10940 360 360
694 10941 4011.75 4011.75
695 10942 560 560
696 10943 711 711
697 10944 1025.3250122070312 1025.33
698 10945 245 245
699 10946 1407.5 1407.5
700 10947 220 220
701 10948 2362.25 2362.25
702 10949 4422 4422
703 10950 110 110
704 10951 458.75500106811523 458.76
705 10952 471.1999969482422 471.2
706 10953 4441.25 4441.25
707 10954 1659.5350646972656 1659.54
708 10955 74.4000015258789 74.4
709 10956 677 677
710 10957 1762.7000122070312 1762.7
711 10958 781 781
712 10959 131.75 131.75
713 10960 265.3500061035156 265.35
714 10961 1119.8999977111816 1119.9
715 10962 3584 3584
716 10963 57.80000305175781 57.8
717 10964 2052.5 2052.5
718 10965 848 848
719 10966 1098.4599914550781 1098.46
720 10967 910.4000015258789 910.4
721 10968 1408 1408
722 10969 108 108
723 10970 224 224
724 10971 1733.06005859375 1733.06
725 10972 251.5 251.5
726 10973 291.5499954223633 291.55
727 10974 439 439
728 10975 717.5 717.5
729 10976 912 912
730 10977 2233 2233
731 10978 1303.1949996948242 1303.19
732 10979 4813.5 4813.5
733 10980 248 248
734 10981 15810 15810
735 10982 1014 1014
736 10983 720.9000244140625 720.9
737 10984 1809.75 1809.75
738 10985 2023.3800048828125 2023.38
739 10986 2220 2220
740 10987 2772 2772
741 10988 3574.7999267578125 3574.8
742 10989 1353.599998474121 1353.6
743 10990 4288.85009765625 4288.85
744 10991 2296 2296
745 10992 69.5999984741211 69.6
746 10993 4895.4375 4895.44
747 10994 940.5 940.5
748 10995 1196 1196
749 10996 560 560
750 10997 1885 1885
751 10998 686 686
752 10999 1197.9499969482422 1197.95
753 11000 903.75 903.75
754 11001 2769 2769
755 11002 1811.1000061035156 1811.1
756 11003 326 326
757 11004 295.3800048828125 295.38
758 11005 586 586
759 11006 329.68499755859375 329.68
760 11007 2633.9000244140625 2633.9
761 11008 4680.89990234375 4680.9
762 11009 616.5 616.5
763 11010 645 645
764 11011 933.5 933.5
765 11012 2825.2999267578125 2825.3
766 11013 361 361
767 11014 243.1800079345703 243.18
768 11015 622.3500061035156 622.35
769 11016 491.5 491.5
770 11017 6750 6750
771 11018 1575 1575
772 11019 76 76
773 11020 632.4000244140625 632.4
774 11021 6306.239990234375 6306.24
775 11022 1402 1402
776 11023 1500 1500
777 11024 1966.8099975585938 1966.81
778 11025 270 270
779 11026 1030 1030
780 11027 877.7250366210938 877.73
781 11028 2160 2160
782 11029 1286.7999877929688 1286.8
783 11030 12615.0498046875 12615.05
784 11031 2393.5 2393.5
785 11032 8902.5 8902.5
786 11033 3232.7999267578125 3232.8
787 11034 539.3999938964844 539.4
788 11035 1754.5 1754.5
789 11036 1692 1692
790 11037 60 60
791 11038 732.5999984741211 732.6
792 11039 3090 3090
793 11040 200 200
794 11041 1773 1773
795 11042 405.75 405.75
796 11043 210 210
797 11044 591.5999755859375 591.6
798 11045 1309.5 1309.5
799 11046 1485.7999877929688 1485.8
800 11047 817.875 817.88
801 11048 525 525
802 11049 273.5999984741211 273.6
803 11050 810 810
804 11051 36 36
805 11052 1332 1332
806 11053 3055 3055
807 11054 305 305
808 11055 1727.5 1727.5
809 11056 3740 3740
810 11057 45 45
811 11058 858 858
812 11059 1838 1838
813 11060 266 266
814 11061 510 510
815 11062 406.3999938964844 406.4
816 11063 1342.949951171875 1342.95
817 11064 4330.399948120117 4330.4
818 11065 189.4199981689453 189.42
819 11066 928.7499923706055 928.75
820 11067 86.8499984741211 86.85
821 11068 2027.080078125 2027.08
822 11069 360 360
823 11070 1629.9750061035156 1629.98
824 11071 484.5 484.5
825 11072 5218 5218
826 11073 300 300
827 11074 232.0850067138672 232.09
828 11075 498.1000003814697 498.1
829 11076 792.75 792.75
830 11077 1255.7205142974854 1255.72


3. Usage of ROUND to round the average price.

SQL Server Query 3

            
SELECT  
c.CategoryID, c.CategoryName,
ROUND(Subquery.AvgPrice, 2) AS RoundedAveragePrice
FROM Categories c
JOIN (
SELECT
CategoryID,
AVG(UnitPrice) AS AvgPrice
FROM Products
GROUP BY CategoryID
) AS Subquery ON c.CategoryID = Subquery.CategoryID
ORDER BY c.CategoryID;

Create SQL query with SqlQueryBuilder 3

            
var (sql3, parameters3) = new SqlQueryBuilder()  
.Select().Columns("c.CategoryID", "c.CategoryName")
.Column(new ROUND(new Column("Subquery.AvgPrice"), 2), "RoundedAveragePrice")
.From("Categories", "c")
.Join(new List<IJoin>()
{
new Join(new SqlQueryBuilder().Select()
.Column("CategoryID", "CategoryID")
.Column(new AVG(new Column("UnitPrice")), "AvgPrice")
.From("Products")
.GroupBy(new GroupBy(new Column("CategoryID"))), "Subquery"
).On(new Column("c.CategoryID").Equale(new Column("Subquery.CategoryID")))
})
.OrderBy(new OrderBy().SetColumnAscending("c.CategoryID"))
.Build();

Query build by SqlQueryBuilder 3

            
SELECT c.CategoryID,
       c.CategoryName,
       ROUND(Subquery.AvgPrice, @pMAIN_2507200213502086140, @pMAIN_2507200213502086141) AS RoundedAveragePrice
FROM Categories AS c
     INNER JOIN
     (SELECT CategoryID AS CategoryID,
             AVG(UnitPrice) AS AvgPrice
      FROM Products
      GROUP BY CategoryID) AS Subquery
     ON c.CategoryID = Subquery.CategoryID
ORDER BY c.CategoryID ASC;


            
        

Parameters (If used)

Name Value
@pMAIN_2507200213502086140 2
@pMAIN_2507200213502086141 0

Query Results 3:

  CategoryID CategoryName RoundedAveragePrice
1 1 Beverages 37.9800
2 2 Condiments 23.0600
3 3 Confections 25.1600
4 4 Dairy Products 28.7300
5 5 Grains/Cereals 20.2500
6 6 Meat/Poultry 54.0100
7 7 Produce 32.3700
8 8 Seafood 20.6800