Skip to content

Instantly share code, notes, and snippets.

@dumindu
Last active January 6, 2019 17:06
Show Gist options
  • Save dumindu/b0b5ff7d7179e81a67ae to your computer and use it in GitHub Desktop.
Save dumindu/b0b5ff7d7179e81a67ae to your computer and use it in GitHub Desktop.
SELECT t.id, COUNT(r.id) AS redeemsCount, r.offerId, t.offerTypeId, r.price, t.discountPercentage, t.discount,
CASE
WHEN t.offerTypeId = 1
THEN SUM(r.price)
WHEN t.offerTypeId = 2
THEN SUM((r.price * t.discountPercentage) / 100)
ELSE SUM(t.discount) END
AS redeemsValue
FROM `Offer` `t`
LEFT JOIN `Redeem` r ON r.offerId = t.id
GROUP BY t.id;
select fk_supplier,
group_concat(COALESCE(fk_group_config, '0') order by fk_address_group)
from supplier_address_group
group by fk_supplier
SELECT
e.event,
substring_index(substring_index(GROUP_CONCAT(e.value ORDER BY e.time DESC), ',', 2) , ',' , 1) - substring_index(substring_index(GROUP_CONCAT(e.value ORDER BY e.time DESC), ',', 2) , ',' , -1)
AS value_text,
COUNT(*) c
FROM events e
GROUP BY e.event
HAVING c > 1
# Build environment
# -----------------
FROM golang:1.11-alpine as build-env
WORKDIR /myapp
RUN apk update && apk add --no-cache --virtual .build-dependencies gcc musl-dev git
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ./bin/api ./cmd/api && \
apk del .build-dependencies
# Running environment
# -------------------
FROM scratch
COPY --from=build-env /myapp/bin/api /myapp/
EXPOSE 8080
CMD ["/myapp/api"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment