SQL - create flag in query to highlight order which contain quantity = 1
up vote
3
down vote
favorite
I have tried creating a case statement but doesn't seem to give me what i want. Id like to get a split of the table (which is at a product level) and aggregate at an order level of items which contain quantity of 1.
Any ideas on how I would do this?
order id | Product | Quantity
---------+---------+--------------
11111 | sdsd4 | 1 (single item )
22222 | sasas | 1 (multiple items)
22222 | wertt | 1 (multiple items)
I'd like to get a case statement to add another column to split out orders with quantity = 1 and orders greater 1
Any idea on how I would do this?
The desired outcome would be the column in (brackets)
I could then count the orders and bring in the newly created column as the dimension
More detail here:
enter image description here
Attached is an image of table structure.
Logic, if quantity = 1 and 1 order then single item order
if order has one item but multiples of same item non single item order
if order has more than one product then non single item order
sql google-bigquery
add a comment |
up vote
3
down vote
favorite
I have tried creating a case statement but doesn't seem to give me what i want. Id like to get a split of the table (which is at a product level) and aggregate at an order level of items which contain quantity of 1.
Any ideas on how I would do this?
order id | Product | Quantity
---------+---------+--------------
11111 | sdsd4 | 1 (single item )
22222 | sasas | 1 (multiple items)
22222 | wertt | 1 (multiple items)
I'd like to get a case statement to add another column to split out orders with quantity = 1 and orders greater 1
Any idea on how I would do this?
The desired outcome would be the column in (brackets)
I could then count the orders and bring in the newly created column as the dimension
More detail here:
enter image description here
Attached is an image of table structure.
Logic, if quantity = 1 and 1 order then single item order
if order has one item but multiples of same item non single item order
if order has more than one product then non single item order
sql google-bigquery
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
It is considered good practice to not use spaces in column names -- I use underscore (_
) myself.
– Hogan
Nov 18 at 19:21
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have tried creating a case statement but doesn't seem to give me what i want. Id like to get a split of the table (which is at a product level) and aggregate at an order level of items which contain quantity of 1.
Any ideas on how I would do this?
order id | Product | Quantity
---------+---------+--------------
11111 | sdsd4 | 1 (single item )
22222 | sasas | 1 (multiple items)
22222 | wertt | 1 (multiple items)
I'd like to get a case statement to add another column to split out orders with quantity = 1 and orders greater 1
Any idea on how I would do this?
The desired outcome would be the column in (brackets)
I could then count the orders and bring in the newly created column as the dimension
More detail here:
enter image description here
Attached is an image of table structure.
Logic, if quantity = 1 and 1 order then single item order
if order has one item but multiples of same item non single item order
if order has more than one product then non single item order
sql google-bigquery
I have tried creating a case statement but doesn't seem to give me what i want. Id like to get a split of the table (which is at a product level) and aggregate at an order level of items which contain quantity of 1.
Any ideas on how I would do this?
order id | Product | Quantity
---------+---------+--------------
11111 | sdsd4 | 1 (single item )
22222 | sasas | 1 (multiple items)
22222 | wertt | 1 (multiple items)
I'd like to get a case statement to add another column to split out orders with quantity = 1 and orders greater 1
Any idea on how I would do this?
The desired outcome would be the column in (brackets)
I could then count the orders and bring in the newly created column as the dimension
More detail here:
enter image description here
Attached is an image of table structure.
Logic, if quantity = 1 and 1 order then single item order
if order has one item but multiples of same item non single item order
if order has more than one product then non single item order
sql google-bigquery
sql google-bigquery
edited Nov 18 at 19:48
jarlh
27.9k52137
27.9k52137
asked Nov 18 at 18:09
Andrew Poole
184
184
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
It is considered good practice to not use spaces in column names -- I use underscore (_
) myself.
– Hogan
Nov 18 at 19:21
add a comment |
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
It is considered good practice to not use spaces in column names -- I use underscore (_
) myself.
– Hogan
Nov 18 at 19:21
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
It is considered good practice to not use spaces in column names -- I use underscore (
_
) myself.– Hogan
Nov 18 at 19:21
It is considered good practice to not use spaces in column names -- I use underscore (
_
) myself.– Hogan
Nov 18 at 19:21
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
Below is for BigQuery Standard SQL
#standardSQL
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
You can test, play with above using dummy data as below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 11111 order_id, 'sdsd4' Product, 1 Quantity UNION ALL
SELECT 22222, 'sasas', 2 UNION ALL
SELECT 22222, 'wertt', 1
)
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
with result
Row order_id Product Quantity Single_or_Multiple
1 11111 sdsd4 1 Single Item Order
2 22222 sasas 2 Multipple Items Order
3 22222 wertt 1 Multipple Items Order
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
add a comment |
up vote
3
down vote
If your database supports analytic functions, then you can use a query like this one:
SELECT *,
CASE WHEN count("Product") OVER (partition by "order id") > 1
THEN 'multiple items' ELSE 'single item'
END As "How many items"
FROM Table1
Demo: https://dbfiddle.uk/?rdbms=postgres_11&fiddle=b659279fc16d2084cb1cf4a3bea361a1
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
add a comment |
up vote
2
down vote
If I understand this right, you could use a subquery to get the count of records for an order and flag a record, if this count is larger then 1 and the quantity is equal to 1.
SELECT t1.order_id,
t1.product,
t1.quantity,
CASE
WHEN t1.quantity = 1
AND (SELECT count(*)
FROM elbat t2
WHERE t2.order_id = t1.order_id) > 1 THEN
'flag'
ELSE
'no flag'
END flag
FROM elbat t1;
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was closet2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better ifgroup by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?
– Himanshu Ahuja
Nov 18 at 20:22
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Below is for BigQuery Standard SQL
#standardSQL
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
You can test, play with above using dummy data as below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 11111 order_id, 'sdsd4' Product, 1 Quantity UNION ALL
SELECT 22222, 'sasas', 2 UNION ALL
SELECT 22222, 'wertt', 1
)
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
with result
Row order_id Product Quantity Single_or_Multiple
1 11111 sdsd4 1 Single Item Order
2 22222 sasas 2 Multipple Items Order
3 22222 wertt 1 Multipple Items Order
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
add a comment |
up vote
2
down vote
accepted
Below is for BigQuery Standard SQL
#standardSQL
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
You can test, play with above using dummy data as below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 11111 order_id, 'sdsd4' Product, 1 Quantity UNION ALL
SELECT 22222, 'sasas', 2 UNION ALL
SELECT 22222, 'wertt', 1
)
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
with result
Row order_id Product Quantity Single_or_Multiple
1 11111 sdsd4 1 Single Item Order
2 22222 sasas 2 Multipple Items Order
3 22222 wertt 1 Multipple Items Order
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Below is for BigQuery Standard SQL
#standardSQL
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
You can test, play with above using dummy data as below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 11111 order_id, 'sdsd4' Product, 1 Quantity UNION ALL
SELECT 22222, 'sasas', 2 UNION ALL
SELECT 22222, 'wertt', 1
)
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
with result
Row order_id Product Quantity Single_or_Multiple
1 11111 sdsd4 1 Single Item Order
2 22222 sasas 2 Multipple Items Order
3 22222 wertt 1 Multipple Items Order
Below is for BigQuery Standard SQL
#standardSQL
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
You can test, play with above using dummy data as below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 11111 order_id, 'sdsd4' Product, 1 Quantity UNION ALL
SELECT 22222, 'sasas', 2 UNION ALL
SELECT 22222, 'wertt', 1
)
SELECT *,
CASE COUNT(DISTINCT Product) OVER(PARTITION BY order_id)
WHEN 1 THEN 'Single Item Order'
ELSE 'Multipple Items Order'
END Single_or_Multiple
FROM `project.dataset.table`
with result
Row order_id Product Quantity Single_or_Multiple
1 11111 sdsd4 1 Single Item Order
2 22222 sasas 2 Multipple Items Order
3 22222 wertt 1 Multipple Items Order
answered Nov 18 at 20:17
Mikhail Berlyant
53.5k42964
53.5k42964
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
add a comment |
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
Nailed it! Brilliant Thanks very much for your help. And for everyone who responded.
– Andrew Poole
Nov 18 at 20:33
1
1
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
glad it worked for you. also consider voting up the answer if it helped you :o)
– Mikhail Berlyant
Nov 18 at 20:33
add a comment |
up vote
3
down vote
If your database supports analytic functions, then you can use a query like this one:
SELECT *,
CASE WHEN count("Product") OVER (partition by "order id") > 1
THEN 'multiple items' ELSE 'single item'
END As "How many items"
FROM Table1
Demo: https://dbfiddle.uk/?rdbms=postgres_11&fiddle=b659279fc16d2084cb1cf4a3bea361a1
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
add a comment |
up vote
3
down vote
If your database supports analytic functions, then you can use a query like this one:
SELECT *,
CASE WHEN count("Product") OVER (partition by "order id") > 1
THEN 'multiple items' ELSE 'single item'
END As "How many items"
FROM Table1
Demo: https://dbfiddle.uk/?rdbms=postgres_11&fiddle=b659279fc16d2084cb1cf4a3bea361a1
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
add a comment |
up vote
3
down vote
up vote
3
down vote
If your database supports analytic functions, then you can use a query like this one:
SELECT *,
CASE WHEN count("Product") OVER (partition by "order id") > 1
THEN 'multiple items' ELSE 'single item'
END As "How many items"
FROM Table1
Demo: https://dbfiddle.uk/?rdbms=postgres_11&fiddle=b659279fc16d2084cb1cf4a3bea361a1
If your database supports analytic functions, then you can use a query like this one:
SELECT *,
CASE WHEN count("Product") OVER (partition by "order id") > 1
THEN 'multiple items' ELSE 'single item'
END As "How many items"
FROM Table1
Demo: https://dbfiddle.uk/?rdbms=postgres_11&fiddle=b659279fc16d2084cb1cf4a3bea361a1
answered Nov 18 at 18:40
krokodilko
27.5k32657
27.5k32657
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
add a comment |
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
1
1
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
The database im using is BigQuery
– Andrew Poole
Nov 18 at 18:49
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
Hi, I tried this but didnt return the desired outcome.
– Andrew Poole
Nov 18 at 19:12
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
This answer looks correct to me and should run on BigQuery.
– Gordon Linoff
Nov 18 at 20:09
add a comment |
up vote
2
down vote
If I understand this right, you could use a subquery to get the count of records for an order and flag a record, if this count is larger then 1 and the quantity is equal to 1.
SELECT t1.order_id,
t1.product,
t1.quantity,
CASE
WHEN t1.quantity = 1
AND (SELECT count(*)
FROM elbat t2
WHERE t2.order_id = t1.order_id) > 1 THEN
'flag'
ELSE
'no flag'
END flag
FROM elbat t1;
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was closet2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better ifgroup by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?
– Himanshu Ahuja
Nov 18 at 20:22
add a comment |
up vote
2
down vote
If I understand this right, you could use a subquery to get the count of records for an order and flag a record, if this count is larger then 1 and the quantity is equal to 1.
SELECT t1.order_id,
t1.product,
t1.quantity,
CASE
WHEN t1.quantity = 1
AND (SELECT count(*)
FROM elbat t2
WHERE t2.order_id = t1.order_id) > 1 THEN
'flag'
ELSE
'no flag'
END flag
FROM elbat t1;
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was closet2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better ifgroup by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?
– Himanshu Ahuja
Nov 18 at 20:22
add a comment |
up vote
2
down vote
up vote
2
down vote
If I understand this right, you could use a subquery to get the count of records for an order and flag a record, if this count is larger then 1 and the quantity is equal to 1.
SELECT t1.order_id,
t1.product,
t1.quantity,
CASE
WHEN t1.quantity = 1
AND (SELECT count(*)
FROM elbat t2
WHERE t2.order_id = t1.order_id) > 1 THEN
'flag'
ELSE
'no flag'
END flag
FROM elbat t1;
If I understand this right, you could use a subquery to get the count of records for an order and flag a record, if this count is larger then 1 and the quantity is equal to 1.
SELECT t1.order_id,
t1.product,
t1.quantity,
CASE
WHEN t1.quantity = 1
AND (SELECT count(*)
FROM elbat t2
WHERE t2.order_id = t1.order_id) > 1 THEN
'flag'
ELSE
'no flag'
END flag
FROM elbat t1;
answered Nov 18 at 18:40
sticky bit
10.9k51629
10.9k51629
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was closet2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better ifgroup by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?
– Himanshu Ahuja
Nov 18 at 20:22
add a comment |
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was closet2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better ifgroup by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?
– Himanshu Ahuja
Nov 18 at 20:22
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
Hey, thanks for the quick reply. I think this is nearly there however, there is just 1 table so no need for a join? Sorry for the lack of info on this. Im a newb
– Andrew Poole
Nov 18 at 18:45
1
1
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was close
t2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better if group by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?– Himanshu Ahuja
Nov 18 at 20:22
@sticky bit You explained a correct way to solve it via corelated subquery. I tried it a while ago but only was close
t2.order_id=t1.order_id
did the trick. But a simple suggestion would it be better if group by
was used for count even I am a little unsure as group by would again aggregate but we want row by row. Any point on that ?– Himanshu Ahuja
Nov 18 at 20:22
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53363990%2fsql-create-flag-in-query-to-highlight-order-which-contain-quantity-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Specify the expected result as well!
– jarlh
Nov 18 at 18:44
It is hard to understand your requirement because you are using terms that are unfamiliar to database engineers. Perhaps you can come up with sample data and the expected output, that would help.
– Laurenz Albe
Nov 18 at 18:44
Ive added desired outcome in pic above and logic. hope this helps.
– Andrew Poole
Nov 18 at 19:11
It is considered good practice to not use spaces in column names -- I use underscore (
_
) myself.– Hogan
Nov 18 at 19:21