Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

SELECT

UserID,
UserName as FirstName,
(SELECT top 1 UserName FROM myTable WHERE UserID = t.UserID and UserNameTyp
e = 'Last Name') as LastName
FROM myTable t
WHERE t.UserNameType = 'First Name'
--------------------------------------------------------------------------SELECT DISTINCT
T1.UserID UserID,
T1.UserName FirstName,
T2.UserName LastName
FROM
Users T1 JOIN Users T2
ON T1.UserID = T2.userID
WHERE
T1.UserNameType = 'FirstName'
AND T2.UserNameType = 'LastName'
--------------------------------------------------------------------------SELECT 'Amex' AS source, SUM(tip) AS sum FROM Amex
UNION
SELECT 'MC' AS source, SUM(tip) AS sum FROM Mc
UNION
SELECT 'Visa' AS source, SUM(tip) AS sum FROM Visa
--------------------------------------------------------------------------SELECT A.Amex, M.MC, V.Visa
FROM
(SELECT SUM(tip) AS Amex FROM Amex WHERE DATE(date) = CURDATE()) AS A,
(SELECT SUM(tip) AS Mc FROM Mc WHERE DATE(date) = CURDATE()) AS M,
(SELECT SUM(tip) AS Visa FROM Visa WHERE DATE(date) = CURDATE()) AS V
--------------------------------------------------------------------------SELECT dateadd(month, x.MonthOffset,0) as [Month], SUM(x.val) as Total
FROM
(
SELECT datediff(month,0, trans.trandate) as MonthOffset, trans.val
FROM trans
) x
GROUP BY MonthOffset
ORDER BY MonthOffset
--------------------------------------------------------------------------$q = "SELECT MONTHNAME(date) AS month, SUM(amount) AS total " .
"FROM orders " .
"WHERE status = 0 " .
"AND YEAR(date) = " . $year . " " .
"GROUP BY month";
---------------------------------------------------------------------------

You might also like