|
|
Firstly - take note of the previous comment about SQL Injection!
Quote: I want the array `$user_tree` to hold (user_id 5) first, then (user_id 6), how to do that? Then you need to order your results by [user_id] e.g.
select *
from @demo
where upline = 2
order by [User_id]; Quote: I want to print **Left_id** first, then only print **Right_id**. May I know how to do it? I'm not entirely sure what you mean here, but it sounds like you want the columns in a different order in your result. In the example above I used select * - that is not actually good practice. It is much better to list the columns that you want, in the order that you want them - this helps protect any code that is using the results from any subsequent changes to the table schema, such as adding a new column.
However, if you mean you want to sort by one column within the "grouping" of another column then you simply add a list of things to sort by.
This example covers both the scenarios above
select Left_id,Right_id
from @demo
order by Upline, [User_id]; If you meant something else then reply to this solution and I will try to help
|
|
|
|
|
I'm writing a function which will join two collections and two filters for each.
public class Teacher
{
public string Id{ get; set; }
public string Name{ get; set; }
public string TeacherFilter{ get; set; }
...
}
public class Student
{
public string Id{ get; set; }
public string Name{ get; set; }
public string StudentFilter{ get; set; }
public string TeacherId{ get; set; }
...
}
public class TeacherStudents
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
public IEnumerable<Student> Students{get;set;}
}
public class TeacherStudents
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
public IEnumerable<Student> Student{get;set;}
}
public class TeacherStudent
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
...
public Student Student{get;set;}
}
Get(string TeacherFilter,string StudentFilter).
Here is how i implement it
var query = teacherCollection.Aggregate().Match(x => x.TeacherFilter== TeacherFilter);
var query1 = query
.Lookup<Teacher, Student, TeacherStudent>(studentCollection, t => t.Id, s => s.TeacherId, l => l.Student)
.Unwind(x => x.Student, new AggregateUnwindOptions<TeacherStudent>())
.Match(x => x.StudentFilter== StudentFilter)
For the teacher collection, useless data has been filter out which will reduce the data size when doing the lookup(join). But for the student collection, the match stage is appended after the lookup. so does all the data from student will join with teacher behind the scenes? is it possible to filter out some student data before the lookup?
|
|
|
|
|
|
why no one answer it?
modified 10-Mar-22 12:12pm.
|
|
|
|
|
You posted it less than 12 hours ago. Half the world won't have woken up and had a chance to to read it yet.
And since questions here are answered by volunteers, nobody is under any obligation to answer it at all, let alone within a defined time limit.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i wanna ask.
i forgot my MySQL root password, so i tried to fix it based from this link:
MySQL :: MySQL and Windows :: 4 Resetting the Root Password: Windows Systems[^]
but it still doesn't work and there's few messages, but there's 1 error msg, i.e.:
Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
in addition, there's also a warning i.e.:
Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
any1 know how to fix this issue..?
|
|
|
|
|
And does the directory 'C:\Program Files\MySQL\MySQL Server 8.0\data\' actually exist?
|
|
|
|
|
no. but the questions is:
1. why it make such error..? (e.g. tries to access non-exist folder)
2. why it doesn't create the folder by itself..?
3. should the folder created manually..? since it didn't mentioned anything in the article about that folder or even error-handling if it occurred
|
|
|
|
|
chipp_zanuff wrote: the questions is:
1. why it make such error..? (e.g. tries to access non-exist folder)
2. why it doesn't create the folder by itself..?
3. should the folder created manually..? since it didn't mentioned anything in the article about that folder or even error-handling if it occurred
- But why did you set the non-existing folder?
- Why do you think the folder should be created by itself? Well, if you really need such a feature then ask the MySQL developers!
- It looks like the folder should be created manually.
|
|
|
|
|
|
i wasn't
have you read the link that i posted?
i run this command:
mysqld --init-file=C:\\mysql-init.txt
and the error occurred
|
|
|
|
|
|
i've created that "data" folder, and run init command.. there was no problem...
but when testing connection, the problem still the same, i.e. below pic..
error connection[^]
know how to fix it?
|
|
|
|
|
The message is self-explanatory: one or more of the IP address, port, userid or password are not valid. Check all your settings.
|
|
|
|
|
one or more of the IP address, port, userid or password are not valid.
??
where did you see this message..? it's not in anything in the picture i shared...
the error msg is:
Failed connect to MySQL bla bla bla...
|
|
|
|
|
The message lists all the values it is trying to use to connect. So it is reasonably safe to assume that one or more of them is not correct. That is the only information you have to work with, so you need to investigate further to discover which one it is.
|
|
|
|
|
Hello database experts,
In SQL Server is an option to update statistics before detaching a database, both using Transact-SQL and management studio wizard.
The purpose and advantage of updating statistics is clear.
My question is that, why should we update statistics before detaching a database? Is there any performance issue in recovery of database while attaching? or something else?
SignatureNotFoundException
|
|
|
|
|
Hello
My query to get a ranked leaderboard works on MYSQL 5.7 but gives me errors now that I upgraded to MYSQL 8.0
mysql> SELECT username,score,level, FIND_IN_SET(score,(SELECT GROUP_CONCAT(score ORDER BY score ASC)FROM highscore WHERE game = 0 AND level = 4 AND user = 10 )) AS rank FROM highscore WHERE game = 0 AND level = 4 AND user = 1 ORDER BY rank LIMIT 10;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near 'rank FROM highscore WHERE game = 0 AND level = 4 AND user = 1 ORDER BY rank LIMI' at line 1
Any ideas?
Thank you Team!
|
|
|
|
|
|
Thank you so much.
Simply changed "rank" to "ranklist" and it has resolved the issue.
|
|
|
|
|
Perhaps you should get together with your classmate / colleague:
I need to generate rank in mysql v5.7.31[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am familiar with SQL Server Activity Monitor. What all I know about it, have been learned by my own experinced. I decided to learn all details about it, and googled many keywords but most of results were a brief. I did not find a comprehensive article or document in detail.
Can anyone send me a well documented link?
For example the task states vary in different articles; Or what head blocker value is (the concept is clear but not the value; I thouth it is SPID but is not)?
SignatureNotFoundException
|
|
|
|
|
After some extra research I found a complete list of state from different sources:
Running - The session is running one or more batches. When Multiple Active Result Sets (MARS) is enabled, a session can run multiple batches. For more information, see Using Multiple Active Result Sets (MARS).
Background - The session is running a background task, such as deadlock detection.
Rollback - The session has a transaction rollback in the process.
Pending - The session is waiting for a worker thread to become available.
Runnable - The session's task is in the runnable queue of a scheduler while waiting to get a time quantum.
Spinloop - The session's task is waiting for a spinlock to become free.
Suspended - The session is waiting for an event, such as I/O, to complete.
Sleeping - A session in the sleeping state means a client connection without an active query.
Dormant - SQL Server is resetting the session. Same as Sleeping, except Dormant also indicates that the SPID has been reset after completing an RPC event. (Replication SPIDs show "DORMANT" when waiting.)
For more information about other columns see:
SQL Server Activity Monitor
I hope it helps others.
SignatureNotFoundException
|
|
|
|
|
I need to get all database names, using SQL script only. I have tried:
SELECT datname FROM pg_database WHERE datistemplate = false and seem to work. I got:
mydb1
mydb2
postgres
mybd1 and mydb2 have been created by me. So far, so good. Now, I need to find all tables under every database, using SQL script only. Is it possible ?
|
|
|
|