Sql databases select command [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am new to databases. And our teacher gave us pretty hard assignment. There are two tables. First table nickname is abilities(of superhero's:) ) and second table name superheros.
We have to select nick of Superhero and his average(medial) range for those who has two abilities?
Image of both tables:
Original here: http://postimg.org/image/85pqbc47n/

I will not give you solution - after all, it's homework and you have to learn something :) But I can give you an advice - try to do one task at a time
first, find those superheroes who has only 2 abilities (actually, you can do this by quering only table with abilities)
second - try to find average range of abilities for all superheroes (here you'll need join)
combine your queries
take a look at join, group by, count and having
Don't feel bad if you can't write it at first attempt, your query is not super easy, but 'm sure you can do this.

You can use HAVING and AVG() for this:
SELECT s.NickName, AVG(a.Range)
FROM abilities a
JOIN superhero s
ON a.ID_SuperHero = s.ID_SuperHero
GROUP BY s.NickName
HAVING COUNT(DISTINCT a.Abilities > 1)

Related

Select and append rows with null value (SQL/VBA) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Can someone help in coding a Access SQL statement/Query where I have a table with columns as shown with Ident No not primary
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------null---------null--------null--------null
1----------------null--------null---------ghi----------jkl----------null--------null
1----------------null--------null---------null---------null--------mno--------pqr
Looking for result as shown below in the query result or a new table.
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------ghi---------jkl--------mno--------pqr
Please Help Thanks in advance
You need to use group by and get the MAX() value for each column like
select `Ident_No`, max(`Data1`), max(`Data2`),
max(`Data3`), max(`Data4`), max(`Data5`), max(`Data6`)
from tbl9999
group by Ident_No
See live here http://rextester.com/CIHY78216

SQL LIKE doesn't find obvious matches [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.

How to display following display table using oracle? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Link http://s17.postimg.org/pdftjpl1r/Event.png
I have above two table.I want to display third table using oracle. I know display those data using java,vector and other stuff.But couldn't code correct oracle code.In the above display table shows data which are >=SYSDATE.
I think it is something like this:
select e.event_name,
min(dt.start_date) as start_date,
min(dt.start_date)||'-'||max(dt.end_date) as FromTo
from event e join
date_table dt
on e.e_id = dt.e_id
group by e.event_name;
You may need use to_char() to convert date/times to the right format. You don't specify wht the types are in the data, so it is hard to say what needs conversion.

SQL Server 2008 - DECLARE function [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
What does the "s" do at the end of line 8 of this query:
http://www.sqlfiddle.com/#!3/f8816/20/0
I can't find it anywhere and the statement won't work without it.
Thanks!
The s is an alias for the result set which allows it to be referenced within the query.
The readability of a SELECT statement can be improved by giving a table an alias, also known as a correlation name or range variable. A table alias can be assigned either with or without the AS keyword:
table_name AS table alias
table_name table_alias
Using table aliases
The s is a table alias. It gives a name to a table or subquery used in the from clause.
SQL Server requires that all subqueries use aliases. Not all databases do.
I strongly encourage you to use them. They often make queries much more readable.
The data set getting created in the from is given the name 's' (similar to putting "AS s") so you can reference it otherwise in the code. Any data sets being created in a from requires a name be given to it, hence why it only works with the 's'.

Get me a SQL quesry to check whether the two table data contents are equal? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having two table A and B of same structure.Both tables is loaded with data.I just want the mismatched row of two tables.,,
I'm certain you could do some gigantic JOIN query for each column and then issue a NOT IN over the result but a simple, pragmatic solution is to:
Write a query that orders the data on several columns (or all)
Export the query executed on each table to a separate text file
Use diff to compare the files with each other
Depending on the RDBMS vendor you may have other options you could consider as well.