I need to find all the clients that have their first order in 2017 and sum up their incomes in 2018. I have issue trying to do that in SQL clause. In my table I have 3 clients, 2 of them first …
Tag: mysql
Get today and yesterday data from mysql
SELECT * FROM att_record2 WHERE DATE(row_datentime)=DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND out_datentime=”0000-00-00 00:00:00″ AND in_datentime!=”0000-00-00 00:00:00″ I want to get data from …
How to calculate hours that a clinic is open taking into account break times
I am using MariaDB 10.3. I am attempting to derive how many hours a clinic is actually open for a given weekday from an provider schedule table. The clinic is considered “closed” if (1) all …
How can I safely create a query that will list column names given a table name, and a connection string which may point to SQL Server or MySQL?
I have the following method at the moment which works for my particular two databases, but I’m not sure if it’s the correct way to achieve my goal of listing column names, or is a bit hacky. One part …
How to write a query to compare current date to created_at timestamps in database?
I would like to write a query to compare created_at timestamp with my current date in Ruby on Rails using ActiveRecord and I don’t quite know how do it yet Date is stored like this -> created_at: …
How to show 5 maximum value after joining two tables?
I have 2 tables: users(uid, rollno, name) results(rid, uid, marks) So I want to show the highest 5 marks holder with their roll no and marks like- MCA-03/17 16 MCA-01/17 15 MCA-04/17 8 MCA-…
MySQL output gives values from different rows
I am working on sql and there are 4 different columns which are pname, Fname,Flastname and amount. It gives the correct outputs for pname and amount but fname and flastname are from different rows …
how to show all result query even though the results are empty
I count my data from database, but I have a problem with the result. the result only displays data that is not empty, while the empty data is not displayed. how do I display data rows that are empty …
SQL join results from GROUP BY and COUNT in 2 tables
Table 1 (VID is unique) VID|UID 99 | 11 56 | 12 52 | 11 24 | 13 14 | 13 To count the records by UID, SELECT count(*),UID from t1 GROUP by UID ———— count(*)|UID 2| 11 1| 12 …
MySQL first_value on varchar column returns records in wrong format
first_value function in MySQL returns varchar column in unexpected format. I got a table ‘test’ with two columns create table test (col1 varchar(10), col2 integer); and has records like this, when …