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 have the following table, and want to write a SQL statement to summarize every Article and Extract Maximum? :
| A | 3 |
| B | 6 |
| A | 4 |
Output: A=7, B=6.
select columnname,sum(columnname),max(expression/columnname)
from tablename
group by columnname
Something like this;
SELECT Article, SUM(Num_Column)
FROM Table_Name
GROUP BY Article
ORDER BY Article
Related
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 7 years ago.
Improve this question
Today i went for my first interview for .Net Developer.
Interviewer asked me one tricky question but I can't able to answer that.
I thought lots on that question but not get any solution on that question.
Question is...
ID | Name
1 | Ram
2 | Prathamesh
3 | Naresh
4 | Dasharath
Update this table with following condition;
If Name's character is less than 6 letters then New value must be like "Ram***"
(* mark will be added until characters length is 6)
and if it more than 6 letters all extra letters should be remove.
Result like this :
ID | Name
1 | Ram*** /* added three * marks */
2 | Pratha /* removed extra letters */
3 | Naresh /* No changes */
4 | Dashar /* removed extra letters */
SELECT LEFT(NAME+'******',6) FROM TABLE
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 7 years ago.
Improve this question
I have following table in my database
---------------------
|ID |Date
---------------------
|15 |2015-07-01
|15 |2015-07-02
|15 |2015-07-03
|18 |2015-07-04
|18 |2015-07-05
|22 |2015-07-06
|22 |2015-07-07
|22 |2015-07-08
I am writing this query
select * from table where date = "2015-07-04";
by this code i can get current id but how can i select next id to my current id.
I know only date and want to retrieve data.
like i have date=2015-07-03 and on that date id=15
so i want result containing all rows related to id=15 and also id next to id=15 that is id=18;
Not Sure.. But, seems like you are looking for this
select max(id)+1 from yourTable;
If you are using Oracle, then create SEQUENCE and use NEXTVAL to get next sequence value. If you are using SQL Server, then you can select AUTO INCREMENT option.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I working on these problems for a class I"m taking, but this one has me stumped. Here is the problem:
--Using the AUTHOR table, write a query that will list all information about authors
--whose first name ends with an “A”. Put the results in descending order of last name,
--and then ascending order by first name. This should be done using a single query.
Here is what I've come up with so far:
SELECT *
FROM author
WHERE(fname LIKE '%A')
ORDER BY lname DESC, fname ASC;
However all I get in the result is the information ordered by last name descending. First name ascending doesn't seem to work.
Any thoughts on what I'm missing? Using Oracle Express 10G, if it matters.
Thanks.
There is nothing wrong with your query. All you have to do is just pay attention to the data :-)
Here is how you would interpret your data output:
--------------+--------------
zzz | john
zza | adam
zaa | bob
ccc | jack
ccc | john
cca | mike
So, ordering works just you instruct Oracle - lname desc, fname acs, but you need to realize that fname asc comes in a picture once lname desc is processed. In other words: ZZZ comes before ZZA , but once CCC is ordered then and only then jack comes before john .
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 need to identify situations in a vacation booking database where an approver and submitter are the same person. Data looks like this:
TIME VACATION BOOKING ACTION NAME
1:00:00 1 SUBMIT Mike
1:01:00 1 APPROVE Mike
1:02:00 2 SUBMIT Jane
1:03:00 2 APPROVE Mike
Is "Count" the most efficient way to do this in SQL Queries?
I would want to "catch" the Mike results in Vacation Booking 1 above.
You could use count, but I would prefer a self-join
SELECT * FROM Bookings B1
INNER JOIN Bookings B2
ON B1.[Vacation Booking]= B2.[Vacation Booking]
AND B1.Action = 'SUBMIT'
AND B2.Action = 'APPROVE'
AND B1.Name = B2.Name
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
we have the below table
COUNTRY TOP_COUNTRY
-------------------
ST. HELENA OTHERS
BARBADOS OTHERS
UNITED STATES UNITED STATES
**RUSSIA OTHERS**
NETHERLANDS OTHERS
**GERMANY OTHERS**
ANGUILLA OTHERS
AUSTRALIA AUSTRALIA
CHINA CHINA
I would like to update TOP_COUNTRY row value for a few countries with the names as shown in COUNTRY column.
For eg:
Right now, we RUSSIA shown as 'OTHERS' in TOP_COUNTRY but i would like to update it to the 'RUSSIA'.
This needs to be done for a couple of values..
Can you please let me know how we can get this done..
You can do:
UPDATE tableName
SET TOP_COUNTRY = COUNTRY
WHERE <YourCLause>
In if you want a list of COUNTRY to be updated you can do:
WHERE COUNTRY IN ("COUNTRY1","COUNTRY2",...);
update [YourTableName] set top_country = 'RUSSIA'
where COUNTRY='RUSSIA'