Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What is the use of DESC command in SQL?
"desc" by itself isn't a command. I suppose you mean "ORDER BY field DESC"
the "desc" means that the results obtained from the query will be showed in descending order.
Example:
Suppose you have a bills table with an id field and a total of 5 rows in that table. Those five rows have id: 1 (row 1), 2 (row 2) and so on. Well with a query of this type:
SELECT id FROM bills ORDER BY id DESC
You will get as query result:
5
4
3
2
1
Why? because you asked for descending order in the query instruction (from highest number to lowest number) in this case.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
i want a mysql select query where i can get first 100 numbers starting from 1 and ending to 100 without CTE or any procedures just want a query only.
When I need a list of integers I use
SELECT help_keyword_id num
FROM mysql.help_keyword
HAVING num BETWEEN 1 AND 100
ORDER BY 1;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
MYSQL how to increment column count if different combination row exist
for example if table have
count user certNo
0 a 001
0 b 886
if same user with different certNo comes then i need to increment count by 1,
like
count user certNo
0 a 001
0 b 886
1 a 673
For legacy MySQL version you can use next query:
select
t.*,
count(t1.certNo) as count
from test t
left join test t1 on t1.user = t.user and t1.certNo < t.certNo
group by t.user, t.certNo;
Test it on SQLize.online
You can use row number():
select row_number() over (partition by user order by certNo) - 1 as count,
user, certNo
from t;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a list of skill ratings
john - 6.2
lucy - 4.3
nikki - 5.7
selena - 7.1
I just want to exclude lucy as hers is the least rating and order the rest by descending order wrt rating, and i dont know the total number of people in the list, so the limit function is not gonna work.
Any help, noob alert
A more general answer than the accepted one would be to use LIMIT and OFFSET to remove any number of highest or lowest ranking rows. Then use another subquery to impose any ordering we want. Something like this:
SELECT *
FROM
(
SELECT *
FROM yourTable
ORDER BY rating
LIMIT 1000000000 OFFSET 1 --skips the lowest rating, but
) t -- we could skip any number of ratings
ORDER BY rating DESC;
Demo
You can use subqueries
First use the inner query to find out the minimum rating then exclude the rating
SELECT *
FROM table
WHERE rating NOT IN (SELECT MIN(rating)
FROM table)
ORDER BY rating DESC
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
say i have a table like this:
Buys(cid: integer, pid: integer, day date)
Each row in this table represents a single purchase, an event when customer with id cid bought product with id pid at the date and time specified by day.
I want to find all the cids of customers who buy each product the same number of times. For example, if a customer has 3 purchases of item 101, that customer must also have 3 purchases of any other item she bought.
You can use the MOD function to see if the remainder of the division of total rows per cid and the distinct pid's is 0.
select cid
from buys
group by cid
having MOD(count(*),count(distinct pid)) = 0
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 6 years ago.
Improve this question
Please help me friends. I have attached a screenshot of my table I wish to count all columns with value 0 or 1 where buno="$busno".
Sorry But I don't have any code. I have database table and I don't know how to query at such condition. In the table you can see fields busno with seat A1,A2,A3,A4,B1,B2......N1,N2,N3 and N4. They have only 2 values 1 and 0. 0 for vacant and 1 for booked. I wish to find out how many seats are left (in numbers like 10 0r 20) for a particular busNo. Are you getting my problem?
Get the result row in PHP with the query buno = "$busno", and iterate resultset in php and count the number you want.