How does distinct work with the following table:
id | id2 | time
-------------------
1 | 5555 | 12
2 | 5555 | 12
3 | 5555 | 33
4 | 9999 | 44
5 | 9999 | 44
6 | 5555 | 33
select distinct * from table
How does distinct work with the following table:
id | id2 | time
-------------------
1 | 5555 | 12
2 | 5555 | 12
3 | 5555 | 33
4 | 9999 | 44
5 | 9999 | 44
6 | 5555 | 33
select distinct * from table
How can i update specific column in table1 only when table2.date is >= NOW(). I tried
UPDATE table1 JOIN table2 ON (table1.ownerid = table2.ownerid) SET table.test = 'disabled' WHERE FROM_UNIXTIME(table2.dateto) <= NOW();
But its seems to now work and no error at all
I am new to mysql. I have downloaded mySql installer 5.7.13 of 320.2mb size. While installing i get error Internal Error(error retrieving product version) the installer will now close. screenshot Please can you help me to fix this.
Thanks in advance!
Is it possible to use an UPDATE statement within the WHERE clause of a SELECT statement?
I would like to execute something like this but it doesn't work:
SELECT * FROM table1 WHERE col1 < (UPDATE table1 SET col2='test' WHERE id=1)
I use mysql_query in PHP.
Is there a command like F9 which goes to previous command to the next command or a way to view all commands used? Using the retrieve command in zeus to go back to the command that was just used, how would i go to forward after using the F9 when i've gotten to far. Instead of restarting my search.
I need to check a value before inserting. However for some reason I can't figure it out. Here's my code:
set @accID = (select id from table2);
IF @accID IS NOT NULL THEN
INSERT INTO task
(account_id)
VALUES (@accID);
END IF;
What is wrong with the code above as it shows invalid sql syntax error?
I have a column datedate format, with 15 min intervals and another column called datavalues with corresponding data. I want to roll up the data values to 1 hr. I am attaching a screen shot. . So my new column should have the aggregated value of "DATA_VALUES" column. and the datetime column should represent just hours but not 15 min. Please help, I have tried cast() to convert to time but not able to proceed further.
I have a table with columns
id, q_id, Question, Answer, Q_Date
I have made a query which concatenates multiple rows having same q_id.
Here is the query:
select q_id, Question, Link, Q_Date,
GROUP_CONCAT(Answer SEPARATOR 'n') as Answer
from ask
group by q_id, Question, Link, Q_Date
What I want to do is order by the id column, but when I select id column, it shows all the rows, UnConcatenated.
please help
Php Select Statement works with id(with unique values) as record selector but will not work if I use a different column(with unique values) as a selector
THIS WORKS
$Idart = "4";
$sql2 = "SELECT * FROM articles where id in ({$Idart})";
$results2 = $conn->query($sql2);
$row2 = $results2->fetch_assoc();
THIS DOES NOT WORK
$Idart = "5-6142-8906-6641";
$sql2 = "SELECT * FROM articles where IDStamp in ({$Idart})";
$results2 = $conn->query($sql2);
$row2 = $results2->fetch_assoc();
I've tried a variety of different things with MYSQL including deleting "id" column and making "IDStamp" the primary key. Any thoughts appreciated.
Trying to figure out how to get this JOIN to work properly. Been sitting here for about 30 minutes. Can someone help me out? I am trying to subtract one form the other, to see the difference between invoice quantity and inventory volume.
SELECT Invoice.NameOfItem, SUM(Inventory.Volume - Invoice.Quantity) As TotalNeeded
FROM Invoice
INNER JOIN Inventory
ON Invoice.NameOfItem=Inventory.NameOfItem
GROUP BY Invoice.NameOfItem;
The issue is the output is incorrect.
SELECT NameOfItem, SUM(Quantity) AS TotalNumberNeeded From Invoice GROUP BY NameOfItem
subtracted from
SELECT NameOfItem, SUM(Volume) AS TotalNumberNeeded From Inventory GROUP BY NameOfItem
Is = -112. The output is currently "992"
I'm running the below code using POSTGRESQL in Jetbrains. I'm trying to output the results in a neat 2 column table (QUARTER, RESULTS) INSIDE the console. When I run the below code, it comes back, but in separate tables, making it annoying to have to consolidate the results from each. Is there a way to get multiple results in the same table so I can copy and paste the results INSIDE the console? Thank you
I'm running
SELECT COUNT(DISTINCT CUSTOMER) as Q216 FROM(
SELECT *
FROM TABLE
WHERE CUSTOMER IN ( SELECT CUSTOMER
FROM temp_08.Unemployment
WHERE TRANSACTION_DATE > '3/31/2016'))
SELECT COUNT(DISTINCT CUSTOMER) as Q116 FROM(
SELECT *
FROM temp_08.COF
WHERE CUSTOMER IN ( SELECT CUSTOMER
FROM temp_08.Unemployment
WHERE TRANSACTION_DATE between '12/31/2015' and '3/31/2016'))
I am currently setting up a website that uses a mysql database having more than 4 crore rows of data. I am using one server for files and separate mysql server. Two servers are having 20 core, 64 gb ram. Meanwhile I could see while executing longest mysql queries my mysql server is using two cores maximum hence it is taking more than 38 seconds to execute my longest query. see the result below.
How can i configure my mysql server so that it uses all the 20 cores to handle the mysql ? How can I achieve this ? Mysql version using 5.6
Atop result below.
There is a small hello world Flask with visit statistics. I managed to count visits with redis, but I also have to add support storing date and number of visits in MySQL database. The current code is: I was trying to access previously created database. Currently I have no idea how to store such info in MySQL.
I was trying to access previously created database. Currently I have no idea how to store such info in MySQL.
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host="redis")
mysql = MySQL()
app.config['MYSQL_DATABASE_USER'] = 'user'
app.config['MYSQL_DATABASE_PASSWORD'] = 'passwd'
app.config['MYSQL_DATABASE_DB'] = 'hello'
app.config['MYSQL_DATABASE_HOST'] = 'mysql'
mysql.init_app(app)
@app.route("/")
def hello():
visits = redis.incr('counter')
html = "<h3>Hello, world!</h3>"
"<b>Visits:</b> {visits}"
"<br/>"
return html.format(visits=visits)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80)
How this can be solved? I will be grateful for any suggestions.
I am trying to write a query that will return counted records from the time they were created. The primary key is a particular house which is unique. Another variable is bidder. The house to bidder relationship is 1:1 but there can be multiple records for each bidder (different houses). Another variable is a count (CASE) of results of previous bids that were won. I want to be able to set the count to return the number of previous bids won at the time each house record was created. Currently, my query logs the overall number of previous bids won regardless of the time the house record was created. Any help would be great! Example:
SELECT h.house_id,
h.bidder_id,
h.created_date,
b.bids_won
FROM house h
LEFT JOIN bid_transactions b
ON h.house_id = b.house_id
LEFT JOIN (
SELECT bidder_id,
COUNT(CASE WHEN created_date IS NOT NULL AND transaction_kind = 'Successful Bid' THEN 1 END) bids_won
FROM bid_transactions
GROUP BY user_id
) b
ON h.bidder_id = b.bidder_id
ORDER BY j.created_date DESC