Avoid unnecessary double wrapping of SELECT statement when used as single function parameter.
This commit is contained in:
parent
22b2901336
commit
d197956271
16 changed files with 97 additions and 77 deletions
|
|
@ -22,20 +22,23 @@ func TestWithRegionalSales(t *testing.T) {
|
|||
SELECT(
|
||||
Orders.ShipRegion,
|
||||
SUM(OrderDetails.Quantity).AS(regionalSalesTotalSales.Name()),
|
||||
).
|
||||
FROM(Orders.INNER_JOIN(OrderDetails, OrderDetails.OrderID.EQ(Orders.OrderID))).
|
||||
GROUP_BY(Orders.ShipRegion),
|
||||
).FROM(
|
||||
Orders.INNER_JOIN(OrderDetails, OrderDetails.OrderID.EQ(Orders.OrderID)),
|
||||
).GROUP_BY(Orders.ShipRegion),
|
||||
),
|
||||
topRegion.AS(
|
||||
SELECT(regionalSalesShipRegion).
|
||||
FROM(regionalSales).
|
||||
WHERE(regionalSalesTotalSales.GT(
|
||||
SELECT(
|
||||
regionalSalesShipRegion,
|
||||
).FROM(
|
||||
regionalSales,
|
||||
).WHERE(
|
||||
regionalSalesTotalSales.GT(
|
||||
IntExp(
|
||||
SELECT(SUM(regionalSalesTotalSales)).
|
||||
FROM(regionalSales),
|
||||
).DIV(Int(50)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)(
|
||||
SELECT(
|
||||
|
|
@ -43,13 +46,17 @@ func TestWithRegionalSales(t *testing.T) {
|
|||
OrderDetails.ProductID,
|
||||
COUNT(STAR).AS("product_units"),
|
||||
SUM(OrderDetails.Quantity).AS("product_sales"),
|
||||
).
|
||||
FROM(Orders.INNER_JOIN(OrderDetails, Orders.OrderID.EQ(OrderDetails.OrderID))).
|
||||
WHERE(Orders.ShipRegion.IN(
|
||||
topRegion.SELECT(topRegionShipRegion)),
|
||||
).
|
||||
GROUP_BY(Orders.ShipRegion, OrderDetails.ProductID).
|
||||
ORDER_BY(SUM(OrderDetails.Quantity).DESC()),
|
||||
).FROM(
|
||||
Orders.
|
||||
INNER_JOIN(OrderDetails, Orders.OrderID.EQ(OrderDetails.OrderID)),
|
||||
).WHERE(
|
||||
Orders.ShipRegion.IN(topRegion.SELECT(topRegionShipRegion)),
|
||||
).GROUP_BY(
|
||||
Orders.ShipRegion,
|
||||
OrderDetails.ProductID,
|
||||
).ORDER_BY(
|
||||
SUM(OrderDetails.Quantity).DESC(),
|
||||
),
|
||||
)
|
||||
|
||||
//fmt.Println(stmt.DebugSql())
|
||||
|
|
@ -75,10 +82,10 @@ SELECT orders.ship_region AS "orders.ship_region",
|
|||
SUM(order_details.quantity) AS "product_sales"
|
||||
FROM northwind.orders
|
||||
INNER JOIN northwind.order_details ON (orders.order_id = order_details.order_id)
|
||||
WHERE orders.ship_region IN ((
|
||||
WHERE orders.ship_region IN (
|
||||
SELECT top_region."orders.ship_region" AS "orders.ship_region"
|
||||
FROM top_region
|
||||
))
|
||||
)
|
||||
GROUP BY orders.ship_region, order_details.product_id
|
||||
ORDER BY SUM(order_details.quantity) DESC;
|
||||
`)
|
||||
|
|
@ -141,19 +148,19 @@ func TestWithStatementDeleteAndInsert(t *testing.T) {
|
|||
testutils.AssertStatementSql(t, stmt, `
|
||||
WITH remove_discontinued_orders AS (
|
||||
DELETE FROM northwind.order_details
|
||||
WHERE order_details.product_id IN ((
|
||||
WHERE order_details.product_id IN (
|
||||
SELECT products.product_id AS "products.product_id"
|
||||
FROM northwind.products
|
||||
WHERE products.discontinued = $1
|
||||
))
|
||||
)
|
||||
RETURNING order_details.product_id AS "order_details.product_id"
|
||||
),update_discontinued_price AS (
|
||||
UPDATE northwind.products
|
||||
SET unit_price = $2
|
||||
WHERE products.product_id IN ((
|
||||
WHERE products.product_id IN (
|
||||
SELECT remove_discontinued_orders."order_details.product_id" AS "order_details.product_id"
|
||||
FROM remove_discontinued_orders
|
||||
))
|
||||
)
|
||||
RETURNING products.product_id AS "products.product_id",
|
||||
products.product_name AS "products.product_name",
|
||||
products.supplier_id AS "products.supplier_id",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue