SQL Query for the player and vsplayer [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Team Table
Player (column)
A
B
C
Expected Output: with Two columns
Player vsPlayer
A B
B C
C A
How to write a sql query to get the exact output as Expected output mentioned above.
Thanks in advance

The normal way to get combination (pairs) is to take all permutations, but where column 1 is less than column 2.
SELECT
l.player,
r.player
FROM
player l
INNER JOIN
player r
ON l.player < r.player
Demo : https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=9ce7af3d0afe89c6434cc2800dfbd2ef

Related

How to fetch data using where clause in SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
There is no error, but the results show the values excluding the row that meets both conditions. The result shows 3, in fact, it should be 4 excluding data that has 22 for age and UK for the country. Any idea why the result is 3, not 4?
SELECT COUNT(*) FROM CUSTOMERS WHERE CUSTOMERS.AGE = '22' OR CUSTOMERS.COUNTRY = 'UK';
You have two customers at the age of 22 and 2 residing in the UK.
This is actually a correct result here - how on earth do you come to the conclusion that you have four people meeting that criteria? If more than one point matches for a database entry, it will only count as one for the result, since it's still the same database entry.

case when with count [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a quick sql data as below,
Customerid,Type
1,Adult
1,Adult
2,Adult
3,Adult
4,Teenager
4,Adult
I want the query that lists those customer no.s that do not have any other Type associated with them. For eg. 1 as only Adult associated with, same with 2. But 3 and 4 have multiple Types associated with them.
I am trying to get an output as below.
Customerid,Type
1,Adult
2,Adult
3,null
How should we tackle this.
You seem to want:
select customerid
, (case when min(type) = max(type) then min(type) end) as type
from table t
group by customerid;

update filed in a table recursively [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following table test
id name formula
--------------------------------
1 A aa+bb+cc
2 aa e+f+g
3 e b
4 f t
5 g 5
How can I update the filed formula to get something like that
id name formula
--------------------------------
1 A b+t+5+bb+cc// update aa=b+t+5
2 aa b+t+5//at first update formula which has id =2
3 e b
4 f t
5 g 5
Your question is too complex. You need to solve several problems before you can actually update anything. You need to be able to:
decompose a formula so that you can get a list of all the operands (do you have to do that in SQL, though?);
distinguish between a reference operand and a constant value (or function?) operand;
determine which reference operands are valid references (exist in the table);
determine the order in which the references must be evaluated.
I suggest you seek help on these problems separately, because Stack Overflow is not a good fit for overly complex questions. (Do try solving them yourself first, though.)

SQL filter using 2 dates + SAS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a dataset that looks like below
ctry | start | end
I have a second dataset b
that has
ctry | start | end
as well as other columns.
I would like to filter the second dataset based on ctry, start and end dates
Am presuming you are looking for some kind of inner join (keep all records in the second dataset, b, if the three columns match those in the first dataset). Try the following approach (one of many):
proc sql;
create table filtered as
select b.*
from first_ds as a /* you never said what your first dataset was called */
inner join b as b
on a.ctry=b.ctry
/* edits following OP comment */
and a.start < b.end
and a.end > b.start;

Django get all rows with same value in column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
how can I filter in Django to get a data row one times if the same value in on column?
columns:
a | b
x | y
a | y
y | s
Want one data row set with y (b) and one data row set with s (b).
If not clear what I mean I edit with SQL script...
EDIT: SELECT DISTINCT b FROM table;
Sorry to be blind...
http://docs.djangoproject.com/en/dev/ref/models/querysets/
Have a nice day.