Skip to content
Advertisement

Tag: group-by

SQL Group by Transpose

I have the following Table charges Using the following query gets my the counts by Charge and Date Is there a way to transpose this to get the following? Thank you. Answer Use conditional aggregation:

min and count without limit

I need to select a receipt with 3 conditions: total receipt > 50 (receipt.total) associated purchases doesn’t include item “cucumbers” (product.pname) the number of suppliers (product.sid) of associated products is the lowest I have the following tables set up: sample data: So far I have the following but it is not getting the receipt with the lowest number of sid:

Conditional Grouping in SQL

This should be easy, but I’m having trouble with it. I have a results table that looks like this: Notice that the pct column sums to 1.0 for each store. Here’s the code to create this table: I’m trying to group the results by store, then by cust_id while creating a new category A&B if the same cust_id has both

Create a column based on conditions in select statement

I have an order table in Postgres with order number and status as column. If a new order is placed the default status were Order placed and Goods Assigned. order 12345 order 543223 I want to know if the order were out from the sender place. So I want to create a column called started and has value Yes if

Group rows on condition PostgreSQL

I have a table with repeated Column1 and Column2 pairs, let’s say this is ‘many-to-many’ table. Also, I have there one extra integer column – Column3. What I want is select conditionally grouped rows, like 1). If pair of Column1 and Column2 have several records contains 5 value among others – then it should be grouped into one row with

Advertisement