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 1 year ago.
Improve this question
My query too much time to execute for fetching data.
SELECT `app`.*, `pat`.`title`, `email_address`, `bad_debtor`, `county`, `date_of_birth`, `dentist_id`, `doctor_id`, `ethnicity`, `first_name`, `middle_name`, `last_name`, `gender`, `pat`.`mobile_phone`, `pat`.`prevent_appointment_booking`, `pat`.`use_email`, `pat`.`use_sms`, `pat`.`recall_method`, `pat`.`status`, `pat`.`pat_id`, `pat`.`active` FROM `patients` `pat` LEFT JOIN `appoiment` `app` ON `pat`.`id` = `app`.`patient_id` WHERE (date(app.start_time) > date(NOW()) - INTERVAL 7 DAY) and `app`.`state` IN ('Completed') and `app`.`patient_id` is not NULL GROUP BY `pat`.`id`
This part
WHERE (date(app.start_time) > date(NOW()) - INTERVAL 7 DAY) and `app`.`state` IN ('Completed') and `app`.`patient_id` is not NULL
the problem is in where clause which takes too much time.
help me to optimize query.
replace app. * with the correct column you need
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 2 years ago.
Improve this question
I've to copy a column in another column, but the result is that only the first row is copied and put in all the rows of the other column
I'm trying to execute this query:
UPDATE gdf_storico Set Data = (SELECT Giorno FROM timestamp)
But that stores the same date in all columns
In SQLite, you can use strftime() with modifier '%s' to convert a date to an epoch timestamp:
select datecol, strftime('%s', datecol) as unix_ts
from mytable
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 4 years ago.
Improve this question
Current Database:
tbl_Order:
ID.........UserName........date
1..........john............march 30 2017
2..........mike............march 31 2017
tbl_Products_In_Order
Order_ID.........Qty_Purchased........UnitPrice........TotalPrice
1...............2.....................1.00.............2.00
1...............3.....................2.00.............6.00
2...............1.....................8.00.............8.00
i need the output to be:
Order_ID...UserName...date............Number_Of_Products.........Total_Qty_All
1..........John.......march 30 2017...2..........................5
2..........mike.......march 31 2017...1..........................1
Can someone help me create the SQL query?
Here is a PostgreSQL solution (but using just basic stuff, so should be same or very similar in most SQL dialects):
SELECT
Order_ID,
UserName,
date,
count(Order_ID) AS Number_Of_Products,
sum(Qty_Purchased) AS Total_Qty_All
FROM
tbl_Products_In_Order AS pio
INNER JOIN tbl_Order AS o ON pio.Order_ID = o.ID
GROUP BY Order_ID, UserName, date
ORDER BY Order_ID
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'm not sure how to approach this problem.
I need to output a table containing just one row with "yes" IF some complex condition is met. How would I got about doing this?
The condition is something like this: "if the age difference between the oldest and youngest professors between 2004 and 2008 is at most 10 years"...
I'm using PostgreSQL.
Thanks.
Based on your description, something like this should work.
SELECT
CASE WHEN
(DATE_PART('year', MAX(Birthdate)) - DATE_PART('year', MIN(Birthdate))) * 12 +
(DATE_PART('month', MAX(Birthdate)) - DATE_PART('month', MIN(Birthdate)))
<= 120 THEN 'Yes'
ELSE 'NO'
END
FROM Professors
WHERE DateEmployed BETWEEN '2004-01-01' AND '2008-12-31';
SQL Fiddle example
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 8 years ago.
Improve this question
I need to get monthly numbers of customers who made 2 or more orders. I'm not that good with postgresql so any help would be appreciated.
Table name is shop_orders
Relevant columns are 'email' - customer, 'status_code' should have value 'CONFIRMED', date - timestamp.
Thank you.
Try this:
select EXTRACT(month FROM datecolumn ) as month,email
from shop_orders
where status_code = 'CONFIRMED'
group by EXTRACT(month FROM datecolumn ),email
having count(1) >2
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 8 years ago.
Improve this question
How can I fetch records every 90 days based on criteria in a case statement?
SELECT
LB.bayview_loan_number Loan_Number,
CASE WHEN DATEDIFF(day, OL.LOAN_ADDED_DT, PH3.SKIPTR) >= 120
AND DATEDIFF(day, OL.LOAN_ADDED_DT, GETDATE()) > 150
AND Con2.LastCon IS NULL THEN **--repeat this step every 90 days** 'LMSKIP'
END AS ST
FROM
CAPMKTS.dbo.Loan_Bayview LB
INNER JOIN
LDG.dbo.LDG_ORIGINAL_LOAN OL ON LB.bvln = OL.ln_no
The best way to run SQL process on a timed basis is by creating scheduled jobs in the SQL Server Agent.